第七题:牛牛拿到了一个藏宝图,顺着藏宝图的指示,牛牛发现了一个藏宝盒,藏宝盒上有一个机关,机关每次会显示两个字符串 s 和 t,根据古老的传说,牛牛需要每次都回答 t 是否是 s 的子序列。注意,子序列不要求在原字符串中是连续的,例如串 abc,它的子序列就有 {空串, a, b, c, ab, ac, bc, abc} 8 种。
输入例子:
x.nowcoder.com ooo
输出例子:
Yes
#include<iostream> #include<string.h> using namespace std; char s1[20]; char s2[20]; int main() { while(scanf("%s%s",s1,s2)>0)//记住这种输入方法 { int l1=strlen(s1); int l2=strlen(s2); int i=0,j=0; for(;i<l1;i++) { if(s1[i]==s2[j]) j++; } if(j==l2) cout<<"Yes"<<endl; else cout<<"No"<<endl; } }