您的位置:首页 > 其它

All in All(POJ--1936

2015-08-11 09:47 323 查看
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".
题意:输入两个字符串s和t,判断s是不是t的子串。
思路:模拟比较两个字符串。
Sample Input
sequence subsequence
person compression
VERDI vivaVittorioEmanueleReDiItalia
caseDoesMatter CaseDoesMatter

Sample Output
Yes
No
Yes
No

#include <cstdio>
#include <queue>
#include <cstring>
#define MAX 100002
using namespace std;
char s[100002],t[100002];
int main()
{
//freopen("oo.text","r",stdin);
while(~scanf("%s %s",s,t))
{
int len1,len2,flag,cnt=0,i=0,j=0;
len1=strlen(s);
len2=strlen(t);
while(1)
{
if(s[i]==t[j])
{
cnt++;
i++;
j++;
}
else
j++;
if(cnt==len1)
{
flag=1;
break;
}
if(j==len2)
{
flag=0;
break;
}
}
if(flag)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}<strong>
</strong>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: