time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
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 aiai, the ii-th letter of bb is bibi, the ii-th letter of cc is cici.
For every ii (1≤i≤n1≤i≤n) you must swap (i.e. exchange) cici with either aiai or bibi. So in total you'll perform exactly nn swap operations, each of them either ci↔aici↔ai or ci↔bici↔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≤t≤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.
Example
input
Copy
4 aaa bbb ccc abc bca bca aabb bbaa baba imi mii iim
output
Copy
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 cici with aiai 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 c1c1 with a1a1, c2c2 with b2b2, c3c3 with b3b3 and c4c4 with a4a4. 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中相同的位置中存在至少2个相同的字母就能完全替换,遍历统计即可。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int t, j;
char a[101], b[101], c[101];
scanf("%d", &t);
while (t--)
{
scanf("%s%s%s", a, b, c);
j = 0;
for (int i = 0; i<strlen(a); i++)
{
if (a[i] == c[i] || b[i] == c[i])
{
j++;
}
}
if (j == strlen(a))
{
printf("YES\n");
}
else
{
printf("NO\n");
}
}
return 0;
}