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 CaseDoesMatterSample Output
Yes No Yes No
#include<iostream>
#include<string.h>
#include<stdio.h>
using namespace std;
char a[1000001],b[1000001];
int main()
{
while(cin>>a>>b)
{
int lena=strlen(a),lenb=strlen(b),j=0;
for(int i=0;i<lenb;i++)
{///判断a是否为b的字串
if(b[i]==a[j])
j++;///匹配成功,a字符串继续移动
if(j==lena)///a被完全匹配,那就是字串了
break;
}
if(j==lena)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}
}
inline char gc()
{
static char buff[100000000],*S=buff,*T=buff;
return S==T&&(T=(S=buff)+fread(buff,1,100000000,stdin),S==T)?EOF:*S++;
}