Topic Link: Click to open the link
The main topic: there is a A, a, two string, there is now an operation can be any one of a character x after the addition of a character y (x! =y), ask if you can change a to B.
First, if a can become B, then a must be a sub-sequence of B, which can be calculated in O (n+m) time.
If a is a sub-sequence of B, it is not possible to determine whether the added characters contain an increase in the case, we only need to judge B from the beginning of a continuous sequence of the same string, is not at the beginning of a also exist, if present, then can be converted from A to B.
#include <cstdio> #include <cstring> #include <algorithm>using namespace std; char s1[100010], s2[ 100010]; int main () { int T, I, J, L1, L2; char ch; Freopen ("1009.in", "R", stdin); Freopen ("9.out", "w", stdout); scanf ("%d", &t); while (t--) { scanf ("%s%s", S1, S2); L1 = strlen (S1); L2 = strlen (s2); i = j = 0; while (I < L1 && J < L2) { if (s1[i] = = S2[j]) { i++; j + +; } else j + +; } if (I < L1) { printf ("no\n"); Continue; } for (j = 1; j < L2; J + +) if (s2[j]! = S2[j-1]) break; for (i = 0; i < J; i++) if (s1[i]! = s2[0]) break; if (i < j) printf ("no\n"); else printf ("yes\n"); } return 0;}
Copyright NOTICE: Reprint Please specify source: Http://blog.csdn.net/winddreams
hdu5414 (2015 + schools)--CRB and string (string match)