藏宝图

来源:互联网 发布:手机淘宝怎么找优惠券 编辑:程序博客网 时间:2024/05/17 23:44

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

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


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

输入例子:
x.nowcoder.comooo

输出例子:
Yes


判断一个字符串是否在另一个字符串中出现过

#include <iostream>#include <string>#include <vector>#include <algorithm>#include <set>#include <string.h>#include <stdio.h>#include <math.h>using namespace std;int main(){    char a[20], b[20];    scanf("%s%s", a, b);    int x = strlen(a), y = strlen(b);    int i, j;    for(i = 0,j = 0; i < x && j < y;)    {        if(a[i] == b[j])        {            ++ i;            ++ j;        }        else            ++ i;    }    if(j == y)        printf("Yes\n");    else        printf("No\n");    return 0;}




0 0
原创粉丝点击