1223B.md (2120B)
1 Source: https://codeforces.com/problemset/problem/1223/B 2 3 B. Strings Equalization 4 5 time limit per test 6 7 1 second 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 You are given two strings of equal length $s$ and $t$ consisting of lowercase Latin letters. You may perform any number (possibly, zero) operations on these strings. 22 23 During each operation you choose two adjacent characters in any string and assign the value of the first character to the value of the second or vice versa. 24 25 For example, if $s$ is "acbc" you can get the following strings in one operation: 26 27 * "aabc" (if you perform $s_2 = s_1$); 28 * "ccbc" (if you perform $s_1 = s_2$); 29 * "accc" (if you perform $s_3 = s_2$ or $s_3 = s_4$); 30 * "abbc" (if you perform $s_2 = s_3$); 31 * "acbb" (if you perform $s_4 = s_3$); 32 33 Note that you can also apply this operation to the string $t$. 34 35 Please determine whether it is possible to transform $s$ into $t$, applying the operation above any number of times. 36 37 Note that you have to answer $q$ independent queries. 38 39 Input 40 41 The first line contains one integer $q$ ($1 \le q \le 100$) — the number of queries. Each query is represented by two consecutive lines. 42 43 The first line of each query contains the string $s$ ($1 \le |s| \le 100$) consisting of lowercase Latin letters. 44 45 The second line of each query contains the string $t$ ($1 \le |t| \leq 100$, $|t| = |s|$) consisting of lowercase Latin letters. 46 47 Output 48 49 For each query, print "YES" if it is possible to make $s$ equal to $t$, and "NO" otherwise. 50 51 You may print every letter in any case you want (so, for example, the strings "yEs", "yes", "Yes", and "YES" will all be recognized as positive answer). 52 53 Example 54 55 Input 56 57 ``` 58 3 59 xabb 60 aabx 61 technocup 62 technocup 63 a 64 z 65 ``` 66 67 Output 68 69 ``` 70 YES 71 YES 72 NO 73 ``` 74 75 Note 76 77 In the first query, you can perform two operations $s_1 = s_2$ (after it $s$ turns into "aabb") and $t_4 = t_3$ (after it $t$ turns into "aabb"). 78 79 In the second query, the strings are equal initially, so the answer is "YES". 80 81 In the third query, you can not make strings $s$ and $t$ equal. Therefore, the answer is "NO".