CRB and String Time limit:2000/1000 MS (java/others) Memory limit:65536/65536 K (java/others)
Total submission (s): 246 Accepted Submission (s): 90
Problem Description CRB has both strings s and T.
In each step, CRB can select arbitrary character C of S and inserts any character d (d≠c) just after it.
CRB wants to convert s to T. But is it possible?
Input There is multiple test cases. The first line of input contains an integer T, indicating the number of the test cases. For the test case there is strings s and T, one per line.
1≤t≤105
1≤|s| ≤|t| ≤105
All strings consist only of lowercase 中文版 letters.
The size of each input file is is less than 5MB.
Output for each test case, output "Yes" if the CRB can convert s to T, otherwise output "No".
Sample Input
4 A B cat cats do do apple aapple
Sample Output
No Yes yes No
Author KUT (DPRK)
Source multi-university Training Contest 10
First ensure that the prefix is the same, and then greedy in reverse order, can match the match, or add.
Finally see if all matches are successful, if there are still characters in T, the right side of the sentence is the same as the beginning.
#include <iostream> #include <algorithm> #include <cstring> #include <cstdio> #define MAXN
100007 using namespace std;
Char S[MAXN],T[MAXN];
int LEF1[MAXN],LEF2[MAXN];
int main () {int TT;
scanf ("%d", &TT);
while (tt--) {scanf ("%s", s);
scanf ("%s", T);
int L1 = strlen (s), L2 = strlen (t);
int flag = 1;
if (s[0]! = t[0] | | L1 > L2) flag = 0;
int i = l1-1,j=l2-1,c1=1,c2=1;
while (s[c1] = = T[c2] && s[c1] = = s[0]&& C1 < L1 && flag) c1++,c2++;
for (; J >= C1; j--) {if (i = = c2-1) break;
if (t[j] = = S[i] && i > 0) i--;
} if (i > c2-1) flag = 0;
if (s[c1-1] = = T[c1]) flag = 0;
if (flag) puts ("Yes");
Else puts ("No");
} return 0; }/* + a B cat cats do do apple aapple AAA aaaaa aaaattaa aaaattaaaa Apple allpple AAA abaaaaa AAA aaabaaa AAA AA
AABAAA * *