CF1301A.Three Strings

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 aia_i, the ii-th letter of bb is bib_i, the ii-th letter of cc is cic_i.

For every ii (1≤i≤n1 \leq i \leq n) you must swap (i.e. exchange) cic_i with either aia_i or bib_i. So in total you'll perform exactly nn swap operations, each of them either ci↔aic_i \leftrightarrow a_i or ci↔bic_i \leftrightarrow b_i (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?

给你三个长度均为 nn 的字符串 aa、bb 和 cc。这些字符串仅由小写英文字母组成。aa 的第 ii 个字母记为 aia_i,bb 的第 ii 个字母记为 bib_i,cc 的第 ii 个字母记为 cic_i。

对每个 ii(1≤i≤n1 \leq i \leq n),你必须将 cic_i 与 aia_i 或 bib_i 中的一个交换(即互换位置)。因此,总共需执行恰好 nn 次交换操作,每次操作要么是 ci↔aic_i \leftrightarrow a_i,要么是 ci↔bic_i \leftrightarrow b_i(其中 ii 遍历所有从 11 到 nn 的整数,含端点)。

例如,若 aa 为 "code",bb 为 "true",cc 为 "help",你可以通过从 aa 中取第 11 个和第 44 个字母、从 bb 中取其余字母,使 cc 变为 "crue"。这样,aa 变为 "hodp",bb 变为 "tele"。

在完成所有这些交换后,是否可能使字符串 aa 恰好等于字符串 bb?

输入格式

The input consists of multiple test cases. The first line contains a single integer tt (1≤t≤1001 \leq t \leq 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.

输入包含多个测试用例。第一行包含一个整数 tt(1≤t≤1001 \leq t \leq 100),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含一个由小写英文字母组成的字符串 aa。

每个测试用例的第二行包含一个由小写英文字母组成的字符串 bb。

每个测试用例的第三行包含一个由小写英文字母组成的字符串 cc。

保证在每个测试用例中,这三个字符串均非空,且长度相同,长度不超过 100100。

输出格式

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.

输出 tt 行,对应所有测试用例的答案。对于每个测试用例:

  • 如果可以将字符串 aa 变为字符串 bb,则输出 "YES"(不带引号);
  • 否则输出 "NO"(不带引号)。

答案中的字母可以是小写或大写。

输入输出样例

  • 输入#1

    4
    aaa
    bbb
    ccc
    abc
    bca
    bca
    aabb
    bbaa
    baba
    imi
    mii
    iim

    输出#1

    NO
    YES
    YES
    NO

说明/提示

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 cic_i with aia_i 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 c1c_1 with a1a_1, c2c_2 with b2b_2, c3c_3 with b3b_3 and c4c_4 with a4a_4. 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.

在第一个测试用例中,无法通过交换使得字符串 aa 恰好变为与字符串 bb 相同。

在第二个测试用例中,应对所有可能的 ii 交换 cic_i 与 aia_i。交换后,aa 变为 "bca",bb 变为 "bca",cc 变为 "abc"。此时字符串 aa 与 bb 相等。

在第三个测试用例中,应交换 c1c_1 与 a1a_1、c2c_2 与 b2b_2、c3c_3 与 b3b_3、c4c_4 与 a4a_4。交换后,字符串 aa 变为 "baba",字符串 bb 变为 "baba",字符串 cc 变为 "abab"。此时字符串 aa 与 bb 相等。

在第四个测试用例中,无法通过交换使得字符串 aa 恰好变为与字符串 bb 相同。

输入解题思路,AI测评打分。不知道怎么写?

首页