This is the question:
In a far away Galaxy of Tilky Way, there was a planet Tarth where the sport of Tompetitive Toding was very popular. According to legends, there lived a setter known to give advanced string manipulation problems disguised as cakewalk problems.
thef, the king of thefland loved the letter 't'. And now, he has made a game on it with his ministers! His ministers would give him 2 strings, a and b. thef has to make them exactly same, for which he can do the following-
Step 1 - He MAY reverse at most one of the strings. (This step is optional, and he can choose to reverse any one of the strings, or leave both of them as it is.)
Step 2 - He replaces the first character of both the current strings to 't'. This operation is compulsory.
He wins if he is able to make both the strings same (i.e. an exact match) after doing these two steps. Given the strings a and b, tell if thef can win or not!
Input:
The first line of input contains T - The number of test cases in the file. The first and only line of every test case contains the 2 strings, a and b separated by a single space.
Output:
For each test case, print Yes if thef wins, else print No
Constraints 1≤T≤104 1≤|a|,|b|≤100, where |a| refers to the length of string a. a and b will have ONLY lower case English alphabets. Subtasks 100 points- Original Constraints.
Sample Input:
3
man nam
abcd ebcd
abd ebf
Sample Output:
Yes
Yes
No
EXPLANATION: For the first test case, you can reverse man to nam and then replace both first characters of both strings to get tam. You could also have reversed nam to man, and then replaced the first two characters to get tan. Either of these two methods leads thef to win the game. For the second test case, you can simply skip reversing any of the strings and just replace the first characters by t to get both the strings as tbcd. The 2 strings cannot be made equal in the third test case.
My code is:
#include <iostream>
using namespace std;
#include <bits/stdc++.h>
#include<string.h>
int main() {
int test;
cin>>test;
while(test--){
string str1{},str2{},str3{};
cin>>str1>>str2;
str3=str2;
str1[0]='t';
str3[0]='t';
if(str1==str3){
cout<<"Yes"<<endl;
}
else{
int len=str2.length();
int n=len-1;
for(int i=0;i<len/2;i++){
swap(str2[i],str2[n]);
n=n-1;
}
str2[0]='t';
if(str2==str1){
cout<<"Yes"<<endl;
}
else{
cout<<"No"<<endl;
}
}
}
return 0;
}
Now when I run it with the test case provided, I get the expected output.
But since I'm doing this problem on Codechef, when I submit it, it runs its own test cases (which is not visible) which my code does not pass. I have tried thinking a lot on what possible case i am not considering.