FJUT-1333

女神花花和XIN GE有个约定,只要今天有(XUE)人(ZHANG)能AK就答应和XIN GE交往,那么最后一题压(YING)轴(YU)题来了:
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".

SampleInput
sequence subsequence
person compression
VERDI vivaVittorioEmanueleReDiItalia
caseDoesMatter CaseDoesMatter

SampleOutput
Yes
No
Yes
No

翻译(机翻)(英语菜鸡)
您已经设计了一种新的加密技术,通过在消息的字符之间插入随机生成的字符串,以一种巧妙的方式对消息进行编码。由于正在申请的专利问题,我们将不详细讨论字符串是如何生成并插入原始消息的。然而,为了验证您的方法,有必要编写一个程序来检查消息是否真的被编码在最后的字符串中。
给定两个字符串s和t,您必须确定s是否是t的子序列,即是否可以从t中删除字符,从而使其余字符的串联为s。

输入
输入包含几个测试用例。每个字符由两个字母数字ASCII字符的字符串s、t指定,用分隔符分隔空白。空白s和t的长度不超过100000。

输出
对于每个测试用例,如果s是t的子序列,则输出“Yes”,否则输出“No”。

样本输入
sequence subsequence
person compression
VERDI vivaVittorioEmanueleReDiItalia
caseDoesMatter CaseDoesMatter

样本输出
Yes
No
Yes
No

#include<stdio.h>
#include<string.h>
using namespace std;
#define N 100100

int main(){
    char s[N],t[N];
    while(~scanf("%s %s",&s,&t)){//两个字符串之间用空格隔开
    int len1=strlen(s);//s的长度
    int len2=strlen(t);//t的长度
    int num=0,a=0;
    for(int i=0;i<len2;i++){
        if(s[a]==t[i]) a++;//使用a作为标记,实现顺着t查找s的字符
    }
    if(a==len1) printf("Yes\n");//如果a=1,说明s是t的子序列
    else printf("No\n");//反之不是
    }
    return 0;
}

容易将题误认为是t中存在s的字符则为子序列。

全部评论

相关推荐

2 收藏 评论
分享
牛客网
牛客企业服务