-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPalindromicSeries.java
More file actions
32 lines (30 loc) · 849 Bytes
/
PalindromicSeries.java
File metadata and controls
32 lines (30 loc) · 849 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/** #number-theory */
import java.util.Scanner;
class PalindromicSeries {
public static boolean isPalindromicSeries(int n) {
char[] digitsArr = String.valueOf(n).toCharArray();
int digits = digitsArr.length;
int digitsSum = 0;
for (int i = 0; i < digits; i++) {
digitsSum += digitsArr[i] - '0';
}
// check
for (int left = 0, right = digitsSum - 1; left < right; left++, right--) {
if (digitsArr[left % digits] != digitsArr[right % digits]) {
return false;
}
}
return true;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int testcases = sc.nextInt();
int n;
boolean ret;
for (int t = 0; t < testcases; t++) {
n = sc.nextInt();
ret = isPalindromicSeries(n);
System.out.println(ret ? "YES" : "NO");
}
}
}