1194C.md (2624B)
1 Source: https://codeforces.com/problemset/problem/1194/C 2 3 C. From S To T 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 three strings $s$, $t$ and $p$ consisting of lowercase Latin letters. You may perform any number (possibly, zero) operations on these strings. 22 23 During each operation you choose any character from $p$, erase it from $p$ and insert it into string $s$ (you may insert this character anywhere you want: in the beginning of $s$, in the end or between any two consecutive characters). 24 25 For example, if $p$ is aba, and $s$ is de, then the following outcomes are possible (the character we erase from $p$ and insert into $s$ is highlighted): 26 27 * aba $\rightarrow$ ba, de $\rightarrow$ ade; 28 * aba $\rightarrow$ ba, de $\rightarrow$ dae; 29 * aba $\rightarrow$ ba, de $\rightarrow$ dea; 30 * aba $\rightarrow$ aa, de $\rightarrow$ bde; 31 * aba $\rightarrow$ aa, de $\rightarrow$ dbe; 32 * aba $\rightarrow$ aa, de $\rightarrow$ deb; 33 * aba $\rightarrow$ ab, de $\rightarrow$ ade; 34 * aba $\rightarrow$ ab, de $\rightarrow$ dae; 35 * aba $\rightarrow$ ab, de $\rightarrow$ dea; 36 37 Your goal is to perform several (maybe zero) operations so that $s$ becomes equal to $t$. Please determine whether it is possible. 38 39 Note that you have to answer $q$ independent queries. 40 41 Input 42 43 The first line contains one integer $q$ ($1 \le q \le 100$) — the number of queries. Each query is represented by three consecutive lines. 44 45 The first line of each query contains the string $s$ ($1 \le |s| \le 100$) consisting of lowercase Latin letters. 46 47 The second line of each query contains the string $t$ ($1 \le |t| \le 100$) consisting of lowercase Latin letters. 48 49 The third line of each query contains the string $p$ ($1 \le |p| \le 100$) consisting of lowercase Latin letters. 50 51 Output 52 53 For each query print YES if it is possible to make $s$ equal to $t$, and NO otherwise. 54 55 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). 56 57 Example 58 59 Input 60 61 ``` 62 4 63 ab 64 acxb 65 cax 66 a 67 aaaa 68 aaabbcc 69 a 70 aaaa 71 aabbcc 72 ab 73 baaa 74 aaaaa 75 ``` 76 77 Output 78 79 ``` 80 YES 81 YES 82 NO 83 NO 84 ``` 85 86 Note 87 88 In the first test case there is the following sequence of operation: 89 90 1. $s = $ ab, $t = $ acxb, $p = $ cax; 91 2. $s = $ acb, $t = $ acxb, $p = $ ax; 92 3. $s = $ acxb, $t = $ acxb, $p = $ a. 93 94 In the second test case there is the following sequence of operation: 95 96 1. $s = $ a, $t = $ aaaa, $p = $ aaabbcc; 97 2. $s = $ aa, $t = $ aaaa, $p = $ aabbcc; 98 3. $s = $ aaa, $t = $ aaaa, $p = $ abbcc; 99 4. $s = $ aaaa, $t = $ aaaa, $p = $ bbcc.