Poj 1936 All in All

111 阅读1分钟

All in All

Time Limit: 1000MS Memory Limit: 30000K
Total Submissions: 29727 Accepted: 12369

Description

You have devised a new encryption technique which encodes a message by inserting between its characters randomly generated strings in a clever way. Because of pending patent issues we will not discuss in detail how the strings are generated and inserted into the original message. To validate your method, however, it is necessary to write a program that checks if the message is really encoded in the final string.

Given two strings s and t, you have to decide whether s is a subsequence of t, i.e. if you can remove characters from t such that the concatenation of the remaining characters is s.\

Input

The input contains several testcases. Each is specified by two strings s, t of alphanumeric ASCII characters separated by whitespace.The length of s and t will no more than 100000.

Output

For each test case output "Yes", if s is a subsequence of t,otherwise output "No".

Sample Input

sequence subsequence
person compression
VERDI vivaVittorioEmanueleReDiItalia
caseDoesMatter CaseDoesMatter

Sample Output

Yes
No
Yes


No







纯水题。。。(脑子里有杂念>_<!,害的我弄了半小时,来首歌放弃一切~~,进正题)。

在输入的时候注意先用gets()输入整题,然后划分。










#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
char a[100010],b[100010],tmp[200010];
int l1,l2,z1,z2;
int main()
{
    int i,n,j,m,bj,k;
    while(gets(tmp)!=NULL)
    {
        z1=z2=0;
        int bj=0;
        for(i=0;tmp[i]!='\0';i++)
        {
            if(tmp[i]!=' '&&!bj)
            {
                a[z1++]=tmp[i];
            }
            else if(bj)
            {
                b[z2++]=tmp[i];
            }
            else if(tmp[i]==' ')
            {
                bj=1;
            }
        }
        m=strlen(tmp);
        a[z1]='\0';
        b[z2]='\0';
        //cout<<m<<"  "<<z1<<"    "<<z2<<endl;
         bj=0;
         i=0;
        for(j=0;j<z2;j++)
        {
           // while(a[i]!='\0')
           // {
                if(a[i]==b[j])
                {
                    i++;
                }
                 if(a[i]=='\0')
                {
                    bj=1;
                    break;
                }
            //    else
           //      i=0;
          //}
        }
        if(bj)
        puts("Yes");
        else
        puts("No");
    }
}