题目:
You are given three strings a, b and c of the same length n. The strings consist of lowercase English letters only. The i-th letter of a is ai, the i-th letter of b is bi, the i-th letter of c is ci.
For every i (1≤i≤n) you must swap (i.e. exchange) ci with either ai or bi. So in total you’ll perform exactly n swap operations, each of them either ci↔ai or ci↔bi (i iterates over all integers between 1 and n, inclusive).
For example, if a is “code”, b is “true”, and c is “help”, you can make c equal to “crue” taking the 1-st and the 4-th letters from a and the others from b. In this way a becomes “hodp” and b becomes “tele”.
Is it possible that after these swaps the string a becomes exactly the same as the string b?
Input
The input consists of multiple test cases. The first line contains a single integer t (1≤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 a.
The second line of each test case contains a string of lowercase English letters b.
The third line of each test case contains a string of lowercase English letters c.
It is guaranteed that in each test case these three strings are non-empty and have the same length, which is not exceeding 100.
Output
Print t lines with answers for all test cases. For each test case:
If it is possible to make string a equal to string b print “YES” (without quotes), otherwise print “NO” (without quotes).
You can print either lowercase or uppercase letters in the answers.
样例:
输入:
4
aaa
bbb
ccc
abc
bca
bca
aabb
bbaa
baba
imi
mii
iim
输出:
NO
YES
YES
NO
题意:
给你3个字符串a, b, c,对于a和b字符串的每个位置,可以和字符串c互换,即a[i]和c[i]互换或者b[i]和c[i]互换,判断最后是否可以使字符串a和字符串b相等。
思路:
大水题,扫一遍即可。
AC代码:
#include<stdio.h>
#include<string.h>
#define ll long long
const int maxn = 100 + 5;
int main()
{
int n; scanf("%d", &n);
while (n--) {
char a[maxn], b[maxn], c[maxn];
scanf("%s", a);
scanf("%s", b);
scanf("%s", c);
int len = strlen(a);
int flag = 0;
for (int i = 0; i < len; i++) {
if (a[i] != b[i]) {
if (a[i] == c[i])
b[i] = c[i];
else if (b[i] == c[i])
a[i] = c[i];
else {
flag = 1;
break;
}
}
else if (a[i] == b[i] && a[i] != c[i]) {
flag = 1;
break;
}
}
if (flag)
printf("NO\n");
else if (strcmp(a, b) == 0)
printf("YES\n");
}
return 0;
}