Test instructions: Give two string A, a, a, and ask if you can turn a string into B string. There is only one operation, that is, to select the one-character C of a string, and to add a character D after C, which requires D and C to be different. The operation can be done many times, or it may not. Ensure that A, B is not empty and A's length is not longer.
Solution: (Do not think of trouble) obviously if the first character is different, there is no solution; set two pointers t1,t2 to a,b,t1 T2 from 0, find different exits, find s2[t2-1]! = s2[t2] (T2 > 0) exit. If T2 points to len2 then there is a solution, if T2 point to 0 is no solution, if s2[t2-1] = = S2[t2] is no solution, otherwise, the T1 from S1 to determine whether the suffix is t2 from the S2 suffix of the sub-sequence: It's gone.
My Code
#include <cstdio>#include <cmath>#include <cstring>using namespace STD;#define N 100010CharS1[n],s2[n];intLens1,lens2;BOOLJudge () {if(s1[0]! = s2[0])return false;intT1 =0, t2 =0; for(; t1 < lens1;) {if(T2 >0&& S2[t2-1]! = S2[t2]) Break;if(S1[T1]! = S2[t2]) Break; t1++, t2++; }if(t2 = = lens2)return true;if(T2 = =0)return false;if(S2[t2-1] = = S2[t2])return false; for(; t1 < lens1 && T2 < lens2;) {if(S1[t1] = = S2[t2]) t1++; t2++; }if(T1 = = lens1)return true;Else return false;}intMain () {intTscanf("%d", &t); for(intKase =1; Kase <= T; kase++) {scanf("%s%s", S1,S2); LENS1 = (int)strlen(S1), Lens2 = (int)strlen(S2);printf("%s\n", Judge ()?"Yes":"No"); }return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
HDU 5414 CRB and String