Links: http://acm.hdu.edu.cn/showproblem.php?pid=5414
Problem DESCRIPTIONCRB has a stringssandT.
In each step, CRB can select arbitrary characterCOfsand insert any characterD(< Span id= "MATHJAX-SPAN-17" class= "Mrow" >d ≠ c ) Just after it.
CRB wants to Convert < Span id= "mathjax-span-23" class= "math" > s to t . But is it possible?
Inputthere is multiple test cases. The first line of input contains an integerT, indicating the number of test cases. For each test case there is stringssandT, one per line.
1≤T≤Ten5
1≤| S| ≤| T| ≤Ten5
All strings consist only of lowercase 中文版 letters.
The size of each input file is is less than 5MB.
Outputfor Each test case, the output "Yes" if CRB can convert s to T, otherwise output "No".
Sample Input4 a B cat cats do do apple aapple
Sample Outputnoyesyesno First Test instructions understand wrong, make long time didn't get out, read someone else's blog just dawned.
1#include <iostream>2#include <cstring>3#include <cstdio>4 using namespacestd;5 6 intN,flag,m,l1,l2;7 Charc[1100000],ch[1100000];8 intMain ()9 {Tenscanf"%d",&n); One while(n--) A { -scanf"%s%s", c,ch); -l1=strlen (c); theL2=strlen (CH); - if(L1>L2)//The length of S is greater than the length of T certainly does not meet the criteria - { -printf"no\n"); + Continue; - } + if(c[0]!=ch[0])//The first character is unequal, which means that it will be inserted at the beginning, not eligible A { atprintf"no\n"); - Continue; - } - inti,j; - for(i=0, j=0; i<l1&&j<l2;j++) - { in if(ch[j]==C[i]) -i++; to } + if(I<L1)//s need to be a substring of T, in order for each character to be found in T - { theprintf"no\n"); * Continue; $ }Panax NotoginsengI=1, j=1; - while(i<l1&&c[i]==c[0]) thei++; + while(j<l2&&ch[j]==ch[0]) AJ + +; the if(I<J)//cannot be inserted the same as the first character, + //For example, S is AAT T for Aaat this case must be inserted after a - { $printf"no\n"); $ Continue; - } -printf"yes\n"); the } - return 0;Wuyi}
HDU 5414 CRB and String