HDU 5414 CRB and String 2015 multi-school Joint Training Tournament # # Greedy

Source: Internet
Author: User
Tags strlen

CRB and String Time limit:2000/1000 MS (java/others) Memory limit:65536/65536 K (java/others)
Total submission (s): 246 Accepted Submission (s): 90


Problem Description CRB has both strings s and T.
In each step, CRB can select arbitrary character C of S and inserts any character d (d≠c) just after it.
CRB wants to convert s to T. But is it possible?

Input There is multiple test cases. The first line of input contains an integer T, indicating the number of the test cases. For the test case there is strings s and T, one per line.
1≤t≤105
1≤|s| ≤|t| ≤105
All strings consist only of lowercase 中文版 letters.
The size of each input file is is less than 5MB.

Output for each test case, output "Yes" if the CRB can convert s to T, otherwise output "No".
Sample Input

4 A B cat cats do do apple aapple
Sample Output
No Yes yes No
Author KUT (DPRK)
Source multi-university Training Contest 10
First ensure that the prefix is the same, and then greedy in reverse order, can match the match, or add.

Finally see if all matches are successful, if there are still characters in T, the right side of the sentence is the same as the beginning.



#include <iostream> #include <algorithm> #include <cstring> #include <cstdio> #define MAXN
100007 using namespace std;
Char S[MAXN],T[MAXN];

int LEF1[MAXN],LEF2[MAXN];
    int main () {int TT;
    scanf ("%d", &AMP;TT);
        while (tt--) {scanf ("%s", s);
        scanf ("%s", T);
        int L1 = strlen (s), L2 = strlen (t);
        int flag = 1;
        if (s[0]! = t[0] | | L1 > L2) flag = 0;
        int i = l1-1,j=l2-1,c1=1,c2=1;
        while (s[c1] = = T[c2] && s[c1] = = s[0]&& C1 < L1 && flag) c1++,c2++;
            for (; J >= C1; j--) {if (i = = c2-1) break;

        if (t[j] = = S[i] && i > 0) i--;
        } if (i > c2-1) flag = 0;
        if (s[c1-1] = = T[c1]) flag = 0;
        if (flag) puts ("Yes");
    Else puts ("No");
} return 0; }/* + a B cat cats do do apple aapple AAA aaaaa aaaattaa aaaattaaaa Apple allpple AAA abaaaaa AAA aaabaaa AAA AA
 AABAAA * *


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.