Codeforces Round #619 (Div. 2)A. Three Strings

A. Three Strings
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
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.

Example
inputCopy
4
aaa
bbb
ccc
abc
bca
bca
aabb
bbaa
baba
imi
mii
iim
outputCopy
NO
YES
YES
NO
Note
In the first test case, it is impossible to do the swaps so that string a becomes exactly the same as string b.

In the second test case, you should swap ci with ai for all possible i. After the swaps a becomes “bca”, b becomes “bca” and c becomes “abc”. Here the strings a and b are equal.

In the third test case, you should swap c1 with a1, c2 with b2, c3 with b3 and c4 with a4. Then string a becomes “baba”, string b becomes “baba” and string c becomes “abab”. Here the strings a and b are equal.

In the fourth test case, it is impossible to do the swaps so that string a becomes exactly the same as string b.

题意:给三个字符串abc 长度len一样 对于每个位置,必须进行ai和ci交换 或者bi和ci进行交换,这样一共进行了len次交换,你可以选择ci和ai还是bi交换,问是不是存在操作 使得字符串a和b相等

思路:一定要交换,所以我们判断a_ic_i 或者 b_ic_i 都满足 就是YES 不然就是NO
a_ic_i 我们可以c_i和b_i交换 b_ic_i 我们可以a_i和c_i交换

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define me(a,x) memset(a,x,sizeof a)
#define pb(a) push_back(a)
#define pa pair<int,int>
#define fi first
#define se second
int main()
{
 
     int t;cin>>t;
     while(t--){
 
       string a,b,c;
       cin>>a>>b>>c;
       int len=a.size();
       int flag=0;
       for(int i=0;i<len;i++){
 
          if( b[i]==c[i] || a[i]==c[i]) continue;
          else {flag=1;break;}
 
       }
       puts(!flag?"YES":"NO");
     }
   return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

我不会c语言

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值