HDU 5414 CRB and String

Source: Internet
Author: User

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&GT;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&LT;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&LT;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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.