728x90
https://www.acmicpc.net/problem/7682
구현문제이다.
# import sys; input = sys.stdin.readline
def check_line(string, player):
ret = False
if player == string[0] == string[1] == string[2]\
or player == string[3] == string[4] == string[5]\
or player == string[6] == string[7] == string[8]\
or player == string[0] == string[3] == string[6]\
or player == string[1] == string[4] == string[7]\
or player == string[2] == string[5] == string[8]\
or player == string[0] == string[4] == string[8]\
or player == string[2] == string[4] == string[6]:
ret = True
return ret
def check_string(string):
win_x, win_o = check_line(string, 'X'), check_line(string, 'O')
num_x, num_o, num_dot = string.count('X'), string.count('O'), string.count('.')
if (win_x and not win_o and num_x == num_o + 1)\
or (not win_x and win_o and num_x == num_o)\
or (not win_x and not win_o and num_x == 5 and num_o == 4):
return "valid"
return "invalid"
def main():
answer = []
while True:
string = input().rstrip()
if string == "end":
break
answer.append(check_string(string))
print(*answer, sep='\n')
if __name__ == "__main__":
main()
'STUDY > Algorithm' 카테고리의 다른 글
[프로그래머스] 단체사진 찍기, 2017 카카오코드 본선, C++ (0) | 2022.05.19 |
---|---|
[백준] 8972 미친 아두이노 python (0) | 2022.04.11 |
[백준] 17609 회문 python (0) | 2022.04.07 |
[백준] 21608 상어 초등학교 C++ (0) | 2022.04.04 |
[백준] 17281 ⚾ C++ (0) | 2022.04.01 |