Time Limit:1000MS Memory Limit:30000KB 64bit IO Format:%I64d & %I64u
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".
Sample Input
sequence subsequence
person compression
VERDI vivaVittorioEmanueleReDiItalia
caseDoesMatter CaseDoesMatter
主要的意思就是前一个字符串中的字母有没有按顺序出现在后面的那个字符串中
#include<stdio.h>
#include<string.h>
using namespace std;
char a[100000];
char b[100000];
int c[100010];
int main()
{
while(cin>>a>>b)
{
int len_a=strlen(a);
int len_b=strlen(b);
int i=0;
int j=0;
while(i<len_a&&j<len_b)
{
if(a[i]==b[j])
{
c[i]++;
i++;
}
j++;
}
int flag=0;
for(int k=0;k<len_a;k++)
{
if(c[k]==0) flag=1;
}
if(flag==0) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
memset(c,0,sizeof(c));
}
return 0;
}