Thef and his Games

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 22 strings, aa and bb. 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 aa and bb, tell if thef can win or not!

Input:

  • The first line of input contains TT - The number of test cases in the file.
  • The first and only line of every test case contains the 22 strings, aa and bb separated by a single space.

Output:

For each test case, print Yes if thef wins, else print No

Constraints

  • 1≤T≤1041≤T≤104
  • 1≤|a|,|b|≤1001≤|a|,|b|≤100, where |a||a| refers to the length of string aa.
  • aa and bb 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 manman to namnam and then replace both first characters of both strings to get tamtam. You could also have reversed nam nam to man man, and then replaced the first two characters to get tantan. 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 tt to get both the strings as tbcd tbcd.
  • The 22 strings cannot be made equal in the third test case.

Author:vijju123_adm

Date Added:10-09-2019

Time Limit:1 secs

Source Limit:50000 Bytes

1 Like

#include<bits/stdc++.h>
using namespace std;
int match(string s)
{
int count=0;
sort(s.begin(),s.end());
for(int i=0; i<s.length()-1; i+=2)
{
if(s[i]!=s[i+1])
{
count++;
i–;
}
}
return count;
}
int main()
{
int t;
cin>>t;
while(t–)
{
string str1,str2;
cin>>str1>>str2;
int count = match(str1+str2);
if(count<=1)
cout<<“YES\n”;
else
cout<<“NO\n”;
}
}

If f decides to swap one of the strings, the order of the characters in it changes, but he must still replace the first character with ‘t’. If the first characters aa and bb are the same, he immediately wins, since they become an exact match. However, if the first characters are different, then changing one of the strings to the opposite one will not help, since the first character of both strings will become ‘t’, but there will be no exact match. Let’s set aside the complexities tonight and just play, I’ve been reading about Multi-Line Slots in Canada https://casinosanalyzer.ca/slots-online/multiline and I think this game would be a good fit for our company. Thus, f can win the game if and only if the first characters aa and bb are the same. Regardless of whether he decides to change one of the strings to the opposite one, if the first characters are the same, they will become an exact match after the second step. If the first symbols are different, it is impossible to win the game.