Problem 018 ——UVa 10340 - All in All

来源:互联网 发布:ios 分页加载数据 编辑:程序博客网 时间:2024/04/30 04:40

Problem E

All in All

Input: standard input

Output: standard output

Time Limit: 2 seconds

Memory Limit: 32 MB

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

Given two strings s and t, you haveto decide whether s is a subsequence oft, i.e. if you can removecharacters from t such that the concatenation of the remainingcharacters iss.

Input Specification

The input contains several testcases. Each isspecified by two strings s, t of alphanumeric ASCII characters separatedby whitespace. Input is terminated by EOF.

Output Specification

For each test case output, if s is asubsequence of t.

Sample Input

sequence subsequence
person compression
VERDI vivaVittorioEmanueleReDiItalia
caseDoesMatter CaseDoesMatter

SampleOutput

Yes
No
Yes
No




#include"iostream"#include"cstdio"#include"cstring"using namespace std;char want[10000008];char real[10000008];int flag(int w,int r){    int pd=0;    for(int i=0,j=0;i<w&&j<r;){        if(want[i]==real[j]) pd++,i++,j++;        else j++;    }    if(pd==w) return 1;    else return 0;}int main(){    while(~scanf("%s",want)){        scanf("%s",real);        int lenw=strlen(want),lenr=strlen(real);        int n=0;        bool pd=flag(lenw,lenr);        if(pd) cout << "Yes" <<endl;        else cout << "No" <<endl;    }    return 0;}


0 0
原创粉丝点击