Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- def find(r,dic):
- return [[i,find(r[len(i):],dic)] for i in dic if (re.match(i,r))]
- def out(a,s='('):
- if(a and type(a)==list):
- for i in a:
- for j in i:
- if(type(j)==list):
- s=out(j,s)
- else:
- s+=" "+j
- else:
- s+=')('
- return s
- T=input()
- for i in range(T):
- a=int(input())
- dic=str(input()).split()
- s=str(input())
- print("Case ",i+1,":")
- print(re.sub('\($','',re.sub('\( ','(',out(find(s,dic)))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement