Permalink
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
70 lines (53 sloc) 1.58 KB
import sys
def min_token(s):
ls=len(s)
token=1
for i in range(ls-1):
if s[i] != s[i+1]:
token=token+1
return token
def ifTransform(m,n):
if not m or not n:
return False
if m[0]=='0' and n[0]=='B':
return False
lm=len(m) #length of 2 string patten
ln=len(n)
if lm>ln:
return False
if lm==ln: #also contains lm==ln==1,
for i in range(ln):
if n[i]=='B':
if m[i]=='0':
return False
return True
if lm<min_token(n):
return False
if lm<ln: # also contans lm=1, ln>1
if lm==1:
for i in range(ln-1):
if n[i]!=n[i+1]:
return False
return True
if n[0]!=n[1]:
return ifTransform(m[1:],n[1:])
return ifTransform(m,n[1:]) or ifTransform(m[1:],n[1:])
test_cases = open(sys.argv[1], 'r')
for test in test_cases:
s1,s2=test.strip().split(' ')
print "Yes" if ifTransform(s1,s2) else "No"
test_cases.close()
# if m[0]=='0': # and n[0]=='A' , implicitly
# if len(n)==1:
# return True
# if n[1]=='B':
# return ifTransform(m[1:],n[1:])
# if n[1]=='A':
# return ifTransform(m[1:],n[1:]) or ifTransform(m[1:],n[2:])
# if m[0]='1':
# if len(n)==1:
# return True
# if n[1]!=n[0]:
# return ifTransform(m[1:],n[1:])
# if n[1]==n[0]:
# return ifTransform(m[1:],n[1:]) or ifTransform(m[1:],n[2:])