CodeForeces-1301 A Three Strings

See this article on my own blog https://dyingdown.github.io/2020/02/14/CodeForeces-1301A-Three-Strings/

A. Three Strings
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output:standard output

You are given three strings a a a, b b b and c c c of the same length n n n. The strings consist of lowercase English letters only. The i − t h i-th ith letter of a a a is a i a_i ai, the i − t h i-th ith letter of b b b is b i b_i bi, the i − t h i-th ith letter of c c c is c i c_i ci.

For every i i i ( 1 ≤ i ≤ n ) (1≤i≤n) (1in) you must swap (i.e. exchange) c i c_i ci with either a i a_i ai or b i b_i bi. So in total you’ll perform exactly n n n swap operations, each of them either c i ↔ a i c_i↔a_i ciai or c i ↔ b i c_i↔b_i cibi ( i i i iterates over all integers between 1 1 1 and n n n, inclusive).

For example, if a a a is “code”, b b b is “true”, and c c c is “help”, you can make c c c equal to “crue” taking the 1 − s t 1-st 1st and the 4 − t h 4-th 4th letters from a a a and the others from b b b. In this way a a a becomes “hodp” and b b b becomes “tele”.

Is it possible that after these swaps the string a a a becomes exactly the same as the string b b b?

Input

The input consists of multiple test cases. The first line contains a single integer t t t ( 1 ≤ t ≤ 100 ) (1≤t≤100) (1t100) — 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 a a.

The second line of each test case contains a string of lowercase English letters b b b.

The third line of each test case contains a string of lowercase English letters c c 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 100 100.

Output

Print t t t lines with answers for all test cases. For each test case:

If it is possible to make string a a a equal to string b b b print “YES” (without quotes), otherwise print “NO” (without quotes).

You can print either lowercase or uppercase letters in the answers.

Example

input
4
aaa
bbb
ccc
abc
bca
bca
aabb
bbaa
baba
imi
mii
iim
output
NO
YES
YES
NO

Note

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

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

In the third test case, you should swap c 1 c_1 c1 with a 1 a_1 a1, c 2 c_2 c2 with b 2 b_2 b2, c 3 c_3 c3 with b 3 b_3 b3 and c 4 c_4 c4 with a 4 a_4 a4. Then string a a a becomes “baba”, string b b b becomes “baba” and string c c c becomes “abab”. Here the strings a a a and b b b are equal.

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

Analysis

Only two conditions exist that make it impossible:

  1. For i-th position, all a i a_i ai b i b_i bi and c i c_i ci are not equal to each other.
  2. a i = b i ≠ c i a_i=b_i \neq c_i ai=bi=ci, so if changed, a i ≠ b i a_i\neq b_i ai=bi

So that are actually one situation: a i ≠ c i a_i \neq c_i ai=ci and b i ≠ c i b_i \neq c_i bi=ci

Code

#include<bits/stdc++.h>
 
using namespace std;
 
int arr[2000000];
int main() {
    int t;
    cin >> t;
    while(t --) {
        string a, b, c;
        cin >> a >> b >> c;
        int flag = 1;
        for(int i = 0; i < a.length(); i ++) {
            if(a[i] != c[i] and b[i] != c[i]) {
                flag = 0;
                break;
            }
        }
        if(flag) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值