You are given three strings aa, bb and cc of the same length nn. The strings consist of lowercase English letters only. The ii-th letter of aa is a_iai, the ii-th letter of bb is b_ibi, the ii-th letter of cc is c_ici.
For every ii (1 \leq i \leq n1≤i≤n) you must swap (i.e. exchange) c_ici with either a_iai or b_ibi. So in total you'll perform exactly nn swap operations, each of them either c_i \leftrightarrow a_ici↔ai or c_i \leftrightarrow b_ici↔bi (ii iterates over all integers between 11 and nn, inclusive).
For example, if aa is "code", bb is "true", and cc is "help", you can make cc equal to "crue" taking the 11-st and the 44-th letters from aa and the others from bb. In this way aa becomes "hodp" and bb becomes "tele".
Is it possible that after these swaps the string aa becomes exactly the same as the string bb?
Input
The input consists of multiple test cases. The first line contains a single integer tt (1 \leq t \leq 1001≤t≤100) — the number of test cases. The description of the test cases follows.
The first line of each test case contains a string of lowercase English letters aa.
The second line of each test case contains a string of lowercase English letters bb.
The third line of each test case contains a string of lowercase English letters cc.
It is guaranteed that in each test case these three strings are non-empty and have the same length, which is not exceeding 100100.
Output
Print tt lines with answers for all test cases. For each test case:
If it is possible to make string aa equal to string bb print "YES" (without quotes), otherwise print "NO" (without quotes).
You can print either lowercase or uppercase letters in the answers.
Sample 1
Inputcopy | Outputcopy |
---|---|
4 aaa bbb ccc abc bca bca aabb bbaa baba imi mii iim | NO YES YES NO |
Note
In the first test case, it is impossible to do the swaps so that string aa becomes exactly the same as string bb.
In the second test case, you should swap c_ici with a_iai for all possible ii. After the swaps aa becomes "bca", bb becomes "bca" and cc becomes "abc". Here the strings aa and bb are equal.
In the third test case, you should swap c_1c1 with a_1a1, c_2c2 with b_2b2, c_3c3 with b_3b3 and c_4c4 with a_4a4. Then string aa becomes "baba", string bb becomes "baba" and string cc becomes "abab". Here the strings aa and bb are equal.
In the fourth test case, it is impossible to do the swaps so that string aa becomes exactly the same as string bb.
题意:
有三个长度相等的字符串a、b、c,可以将c任意位置的字母替换a中对应位置,并且将c其余位置的字母替换b中对应位置,问能否使a、b相同。
思路:
对于每一个位置,只要a[i]==c[i] || b[i]==c[i],就能通过替换使a[i]=b[i]。
代码:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<string>
#include<cmath>
#include<map>
using namespace std;
typedef long long ll;
void slove()
{
int t;
cin>>t;
while(t--)
{
string a,b,c;
cin>>a>>b>>c;
int flag=1;
for(int i=0;i<a.size();i++)
{
if(a[i]==c[i]||b[i]==c[i])
continue;
flag=0;
}
if(flag)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}
}
int main()
{
slove();
}