Diff b/w below 2 programs for Problem Code:CHEFSTLT

The following codes is giving WA:

for _ in range(int(input())):
    a = input()
    b = input()
    m1,m2 = 0,0
    for i in range(len(a)):
        if a[i]!='?' and b[i]!='?' and a[i]!=b[i]:
            m1+=1
        else:
            m2+=1
    print(m1,m1+m2)

The following code is giving AC:

for _ in range(int(input())):
    a = input()
    b = input()
    m1,m2 = 0,0
    for i in range(len(a)):
        if a[i]!='?' and b[i]!='?':
            if a[i]!=b[i]:
                m1+=1
        else:
            m2+=1
    print(m1,m1+m2)

What is the difference between following??? for the problem https://www.codechef.com/problems/CHEFSTLT

 if a[i]!='?' and b[i]!='?' and a[i]!=b[i]:
       m1+=1

  if a[i]!='?' and b[i]!='?':
       if a[i]!=b[i]:
            m1+=1

1st one contains 3 lines which 2nd one contain only 2 lines…:slight_smile:

suppose a[i]=b[i], then in first code else code executed and hence m2+=1 .
while in 2nd code else will not execute and hence m2 will not be changed

3 Likes

Wow, oops I missed that point @gjaiswal108 :smile: . Thank you :wink: