for _ in range(int(input())):
s1=input()
s2=input()
i,p=0,0
while i<len(s1):
if s1[i]==’?’ or s2[i]==’?’:
i+=1
continue
elif s1[i]==s2[i]:
p=1
i+=1
continue
else:
p=0
i+=1
break
i+=1
if p==0:
print('No')
else:
print('Yes')
for _ in range(int(input())):
s1=input()
s2=input()
i,p=0,0
while i<len(s1):
if s1[i]==’?’ or s2[i]==’?’:
i+=1
continue
elif s1[i]==s2[i]:
p=1
i+=1
continue
else:
p=0
i+=1
break
i+=1
if p==0:
print('No')
else:
print('Yes')
Put p=1
inside first if
block as well. Because currently, you are ignoring the case where any string starts with ‘?’ itself without any matching characters in the beginning. For example, if X = “a?” and Y = “??” your code gives NO where as it should have been YES. Below version of your code works:
for _ in range(int(input())):
s1=input()
s2=input()
i,p=0,0
while i<len(s1):
if s1[i]=='?' or s2[i]=='?':
p=1 # you were missing this line
i+=1
continue
elif s1[i]==s2[i]:
p=1
i+=1
continue
else:
p=0
i+=1
break
i+=1
if p==0:
print('No')
else:
print('Yes')
Hey @axelblaze1995
Please follow these 2 steps:
1.Run the for loop from [0…len] where len is the length of the strings.
If both s[i] and t[i] are not equal to ‘?’, you check if they are equal or not. If they are not equal, then you know that the answer is a “No”.
2. If you have reached the end of the string and all characters match, then the answer is “Yes”.
Note:
Please look at my solution for better understanding.
Good luck.
thanks man