-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path16925_문자열추측.py
41 lines (40 loc) · 933 Bytes
/
16925_문자열추측.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
import sys
input = sys.stdin.readline
n = int(input().strip())
alpa = [input().strip() for _ in range((n-1)*2)]
first = []
second = []
for idx in alpa:
if len(idx) == 1:
first.append(idx)
if len(idx) == n-1:
second.append(idx)
db = set()
for i in first:
for j in second:
db.add(i + j)
db.add(j + i)
db = list(db)
ix = 0
ans = ''
while(len(ans) != 2*(n-1)):
ans = ''
want = db[ix]
a = {i:True for i in range(1, n)}
for idx in alpa:
find = False
if a[len(idx)]: # p테스트
for i in range(1, n):
if idx == want[:i]:
a[len(idx)] = False
ans += 'P'
find = True
break
if not find:
for i in range(0, n):
if idx == want[i:n]:
ans += 'S'
break
ix += 1
print(want)
print(ans)