[Python] codeforces edu90 B. 01 Game

B. 01 Game

문제 링크

풀이 코드

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
# B. 01 Game


import sys
input = sys.stdin.readline

t = int(input())

for _ in range(t):
    s = list(input().rstrip())
    turn = False  # F for Alice, T for Bob
    i = 0
    while True:
        # if s empty
        if not s:
            break
        # all 0
        if '1' not in s:
            break
        # all 1
        if '0' not in s:
            break
        if s[i] != s[i+1]:
            del s[i:i+2]
            i = 0
            turn = not turn
        else:
            i += 1
    # print(turn)
    if turn:
        print('DA')
    else:
        print('NET')

비고