hdu5414 (2015 + schools)--CRB and string (string match)

Source: Internet
Author: User

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)

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.