您的位置:首页 > 其它

Uva 10340 - All in All

2016-07-26 17:17 363 查看

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

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

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

题目比较简单,题意大致是给定两个字符串s,t,如果s的字母在t中都出现了,并且是按照s的正序排列的,则输出YES

这题需要注意的是循环控制,如果不对第二个字符串t进行处理将会超时,我这里定义了一个m,m表示检测到相同字母的位置,下一次循环则从m+1检测

#include <cstdio>
#include <cstring>
#define maxn 100000

int main()
{
char s[maxn],t[maxn];
while(scanf("%s%s",s,t)!=EOF)
{
int cnt=0;int m=0;
for(int i=0; i<strlen(s); i++)
{
for(int j=m; j<strlen(t); j++)
{
if(s[i]==t[j])
{
cnt++;
m=j+1;
break;
}
t[j]=' ';
}
}
if(cnt==strlen(s))
printf("Yes\n");
else
printf("No\n");
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  uva