WA in simple operations April Cookoff

I’ getting wrong answer in my code.Could anyone please tell me why it’s giving wrong answer.

This is the question link.

Below is my code.

#include <bits/stdc++.h>
using namespace std;

int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin>>t;
while(t–)
{
string A,B;
cin>>A>>B;
int l = 0,k = 0;
for(int i = 0; A[i] != ‘\0’; ++i)
if(A[i] != B[i])
{
while(A[i] != ‘\0’ && A[i] != B[i])
{
++l;
++i;
}
++k;
if(A[i] == ‘\0’)
break;
}
cout<<(1LLkl)<<“\n”;
}
return 0;
}

Thanks.

Can you please provide the link to your submission? Nevermind, got it.

A testcase for which your code fails
1
ababa
cbcbc

The output is 9, but it’s supposed to be 5.

Remember, the answer should never exceed the length of A, as you can perform an operation the whole string.

1 Like

I had the same problem in the contest. Though I came up with the answer 45 minutes later after working out quite a lot. Look at the editorial to the problem, its really nice.

And yes, first try then look at the editorial.

1 Like

Ummmm… that’s not the only case in his problem, you are right, but there is another case. For example look at the following example.

Input

1
ababbbbbbbbbbbba
bbbbbbbbbbbbbbbb

Output According To You

9

Expected Output

8

Explanation

Take the first 3 and the last one.
Total Length = 4
Islands = 2
Answer = 4 * 2 = 8

1 Like

I never mentioned the logic for the solution :thinking:
I just said that the output can never exceed the length of the string

1 Like

Ya, my bad…misread your post.