File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change
1
+ testcase = int (input ())
2
+
3
+ for i in range (testcase ):
4
+ text = input ()
5
+ left_idx = 0
6
+ right_idx = len (text )- 1
7
+ chance = True
8
+ check = True
9
+ while (left_idx <= right_idx ):
10
+ if check == False :
11
+ break
12
+ # print(left_idx,right_idx)
13
+ if text [left_idx ] == text [right_idx ]: # 왼쪽 오른쪽 같을 경우
14
+ left_idx += 1
15
+ right_idx -= 1
16
+ else : # 왼쪽 오른쪽 다를 경우
17
+ if left_idx < right_idx - 1 : # 인덱스 확인하기
18
+ temp = text [:right_idx ] + text [right_idx + 1 :]
19
+ if temp [:] == temp [::- 1 ]:
20
+ chance = False
21
+ break
22
+ # 왼쪽 문자열 제거
23
+ if left_idx + 1 < right_idx :
24
+ temp = text [:left_idx ] + text [left_idx + 1 :]
25
+ if temp [:] == temp [::- 1 ]:
26
+ chance = False
27
+ break
28
+ check = False
29
+ break
30
+ if check == False :
31
+ print (2 )
32
+ elif check == True and chance == False :
33
+ print (1 )
34
+ elif check == True and chance == True :
35
+ print (0 )
You can’t perform that action at this time.
0 commit comments