网易2017内推笔试编:藏宝图

来源:互联网 发布:北京优化 编辑:程序博客网 时间:2024/06/08 21:01

声明:题目来自传送门

代码是我自己写的,

牛牛拿到了一个藏宝图,顺着藏宝图的指示,牛牛发现了一个藏宝盒,藏宝盒上有一个机关,机关每次会显示两个字符串 s 和 t,根据古老的传说,牛牛需要每次都回答 t 是否是 s 的子序列。注意,子序列不要求在原字符串中是连续的,例如串 abc,它的子序列就有 {空串, a, b, c, ab, ac, bc, abc} 8 种。

输入描述:

每个输入包含一个测试用例。每个测试用例包含两行长度不超过 10 的不包含空格的可见 ASCII 字符串。

输出描述:

输出一行 “Yes” 或者 “No” 表示结果。

输入例子:

group.jobbole.com
ooo

输出例子:

Yes


#include <iostream>#include <cstring>using namespace std;int main( ){freopen("/home/liyuanshuo/ClionProject/hihocoder/in.in", "r" , stdin );char s1[10010], s2[100];cin>>s1;cin>>s2;bool  ans = false;int tmpl = 0;for (int i = 0 ; i < strlen( s1 ) ; ++i ){if( s1[i] == s2[tmpl] )tmpl++;}if ( tmpl == strlen( s2 ) )ans = true;if( ans )cout<<"YES"<<endl;elsecout<<"NO"<<endl;return 0;}


0 0