UVa 10340 All in All(子序列)

来源:互联网 发布:javascript dom教程 编辑:程序博客网 时间:2024/05/31 20:51

Description

Download as PDF

All in All

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 Specification

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

Output Specification

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

Sample Input

sequence subsequence
person compression
VERDI vivaVittorioEmanueleReDiItalia
caseDoesMatter CaseDoesMatter

Sample Output

Yes
No
Yes
No

Source: ULM Local Contest

这是我这个专题最先A的一个,大水题无疑。。。但还是WA了一次。。。不对,是RE了,因为数组开小了(但是题上真心没给范围啊)= =

一看示例,这就是一个大小写敏感的子序列的问题啊,果断手敲代码完成,上代码:

#include <iostream>#include <cstring>using namespace std;bool isSubString(char sub[],char str[]); //用于判断两个参数前者是否为后者的子序列int main(){char str[111111];//就这俩数组,开大点不花钱 = =char sub[111111];while(cin>>sub>>str){if(isSubString(sub,str))cout<<"Yes"<<endl;elsecout<<"No"<<endl;}return 0;}bool isSubString(char sub[],char str[]){int n,i;char *p;//用游动指针来限定可搜寻的起始位置n=strlen(sub);for(i=0,p=str;i<n;i++,p++)if(!(p=strchr(p,sub[i])))//只要sub串中有一个字符在p(str的限定)中未搜寻到,strchr()为NULL,则返回falsereturn false;return true;//如果能循环到底说明在str串中能够搜寻到sub的所有字符,返回true}



0 0
原创粉丝点击