-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBOJ_17609.java
More file actions
48 lines (42 loc) · 1.37 KB
/
Copy pathBOJ_17609.java
File metadata and controls
48 lines (42 loc) · 1.37 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// BOJ - 17609
// Problem Sheet - https://www.acmicpc.net/problem/17609
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
int numberOfTestCases = Integer.parseInt(bf.readLine());
for(int i=0 ; i<numberOfTestCases ; i++) {
String word = bf.readLine();
int start = 0;
int end = word.length()-1;
int result = 0;
while(start <= end) {
if(word.charAt(start) != word.charAt(end)) {
if(isPalindrome(word, start+1, end) || isPalindrome(word, start, end-1)) {
result = 1;
} else {
result = 2;
}
break;
}
start++;
end--;
}
sb.append(result).append("\n");
}
System.out.println(sb);
bf.close();
System.exit(0);
}
private static boolean isPalindrome(String word, int start, int end) {
while(start <= end) {
if(word.charAt(start) != word.charAt(end)) {
return false;
}
start++;
end--;
}
return true;
}
}