-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path회문.py
61 lines (52 loc) · 1.21 KB
/
회문.py
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
49
50
51
52
53
54
55
56
57
58
59
60
61
n = int(input())
strlst = []
for i in range(n):
strlst.append(list(input()))
for str in strlst:
l = len(str)
hl = l//2
flag = [1,2,2]
# abcba
''' [팰린드롬, 유사p tail, 유사p head]
axbcba
a a [1,2,2]
x b [0,1,1]
b b [-1,1,0]
cc [-2,1,-1]
'''
for i in range(hl+1):
if l == 3:
if str[0] != str[2]:
if str[0] == str[1] or str[1] == str[2]:
flag[0] = 0
else:
flag[0] = 0
flag[1] = 0
flag[2] = 0
break
if l == 4 and i == hl:
break
tail = str[i]
head = str[-i-1]
if flag[1] !=2:
phead = str[-i-2]
else:
phead = str[-i-1]
if flag[2] != 2:
ptail = str[i+1]
else:
ptail = str[i]
if head != tail:
flag[0] -=1
if phead != tail:
flag[1] -=1
if ptail != head:
flag[2] -= 1
if max(flag) < 0:
break
if flag[0] == 1:
print(0)
elif flag[1] > 0 or flag[2] > 0:
print(1)
else:
print(2)