All in All(字符串匹配)

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 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 stringssandt, you have to decide whethersis a subsequence oft, i.e. if you can remove characters fromtsuch that the concatenation of the remaining characters iss.

Input Specification

The input contains several testcases. Each is specified by two stringss, tof alphanumeric ASCII characters separated by whitespace. Input is terminated by EOF.

Output Specification

For each test case output, ifsis a subsequence oft.

Sample Input

sequence subsequenceperson compressionVERDI vivaVittorioEmanueleReDiItaliacaseDoesMatter CaseDoesMatter

Sample Output

YesNoYesNo

Source: ULM Local Contest

题意:问第一个串是不是能在第二个串里找出来,不一定是连续的。

#include <stdio.h>#include <string.h>#include <stdlib.h>#include <iostream>#include <algorithm>#include <set>#include <queue>#include <stack>#include <map>using namespace std;const int inf=0x3f3f3f3f;int main(){string str1,str2;int i,j;while(cin>>str1>>str2){int len1=str1.length();int len2=str2.length();int cnt=0;i=j=0;while(i<len1&&j<len2){if(str1[i]==str2[j]){i++;j++;cnt++;}elsej++;}//printf("i==%d j==%d\n",i,j);//printf("cnt==%d\n",cnt);if(cnt==len1)printf("Yes\n");elseprintf("No\n");}return 0;}

,只有在前进中不断学会选择,学会体会,学会欣赏。

All in All(字符串匹配)

相关文章:

你感兴趣的文章:

标签云: