輸入兩個字符串s和t,判斷是否可以從t中刪除0個或者多個字符(其他字符順序不變),得到字符串s。例如,abcde可以得到bce,但無法得到cb。
Input
輸入多組數據
每組一行包含兩個字符串s和t,兩字符串之間用空格隔開。
字符串長度在100000以內
Output
輸出Yes或No
Sample Input
sequence subsequence
person compression
VERDI vivaVittorioEmanueleReDiItalia
caseDoesMatter CaseDoesMatter
Sample Output
Yes
No
Yes
No
思路:略水,直接依次比較就行了
#include <iostream>
#include<cstring>
#include<cstdio>
using namespace std;
char str[1000010],pat[1000010];//pat爲模式串,str爲主串
int charge()
{
int len1=strlen(str),len2=strlen(pat);
int i=0,j=0,count=0;
if(len1<len2)
return 0;
for(;i<len1;++i)
{
if(str[i]==pat[j])
++j;
}
if(j==len2)
return 1;
return 0;
}
int main()
{
while(scanf("%s%s",pat,str)!=EOF)
{
int i= charge();
if(i)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}