euphoriaO-O

[Python] SWEA 1234 비밀번호 본문

Programming/Algorithm

[Python] SWEA 1234 비밀번호

euphoria0-0 2020. 7. 11. 01:30

나의 잘못된 코드: 런타임 에러

for t in range(1,11):
    n,s = int(input()), input()
    while tmp != s:
        tmp = s
        s = s.replace('00', '').replace('11', '').replace('22', '').replace('33', '').replace('44', '').replace('55', '').replace('66', '').replace('77', '').replace('88', '').replace('99', '')
    print('#%d %s' % (t, s))

Stack을 이용한 코드

for t in range(1,11):
    n,s = input().split()
    answer = ''
    for ss in s:
        if len(answer) >  0 and answer[-1] == ss:
            answer = answer[:-1]
        else:
            answer += ss
    print('#%d %s' % (t, answer))

출처 https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV14_DEKAJcCFAYD&categoryId=AV14_DEKAJcCFAYD&categoryType=CODE

Comments