2020/03/18

[zerojudge] e924: pC. 括號配對

from sys import stdin

chk =  ['()','[]','<>','{}']

T = int(stdin.readline())
for _ in range(T):
    s = stdin.readline().strip()
    while(s):
        p1 = len(s)
        for z in chk: s = s.replace(z, '')
        p2 = len(s)
        if(p2 == p1): break
        # p2 == p1 表示找不到成對的括號
        
    print('N' if s else 'Y')

沒有留言:

張貼留言