HDU 5414 CRB and String

Source: Internet
Author: User

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

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.