Skip to content

Commit d28004c

Browse files
authored
Merge pull request #566 from AlgorithmWithGod/LiiNi-coder
[20250728] BOJ / G5 / 회문 / 이인희
2 parents 7e45bd1 + dd973a9 commit d28004c

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
```java
2+
import java.io.BufferedReader;
3+
import java.io.IOException;
4+
import java.io.InputStreamReader;
5+
import java.util.Arrays;
6+
import java.util.PriorityQueue;
7+
8+
import java.io.*;
9+
import java.util.*;
10+
11+
public class Main {
12+
public static void main(String[] args) throws IOException {
13+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
14+
int T = Integer.parseInt(br.readLine());
15+
16+
for(int t = 0; t<T; t++) {
17+
String s = br.readLine();
18+
System.out.println(check(s));
19+
}
20+
}
21+
static boolean ishwae(String s, int left, int right) {
22+
while (left < right) {
23+
if (s.charAt(left) != s.charAt(right)) return false;
24+
left++;
25+
right--;
26+
}
27+
return true;
28+
}
29+
30+
static int check(String s) {
31+
int left = 0;
32+
int right = s.length() - 1;
33+
34+
while (left < right) {
35+
if (s.charAt(left) == s.charAt(right)) {
36+
left++;
37+
right--;
38+
} else {
39+
if (ishwae(s, left + 1, right) || ishwae(s, left, right - 1)) {
40+
//유사회문
41+
return 1;
42+
} else {
43+
return 2;
44+
}
45+
}
46+
}
47+
return 0;
48+
}
49+
50+
51+
}
52+
```

0 commit comments

Comments
 (0)