All in All
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 29339 | Accepted: 12170 |
Description
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.
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".
Sample Input
sequence subsequence person compression VERDI vivaVittorioEmanueleReDiItalia caseDoesMatter CaseDoesMatter
Sample Output
Yes No Yes No
Source
问第一个字符串包含在第二中么
直接暴力吧
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#include <stdlib.h>
using namespace std;
#define Max 100010
char t1[Max],t2[Max];
int al[233];
int bl[233];
int main()
{
while(~scanf("%s%s",t1,t2))
{
int l1=strlen(t1);
int l2=strlen(t2);
int flag=0;
long long pos_1=0,pos_2=0;
while(1)
{
if(pos_1==l1)
{
flag=1;
break;
}
else if(pos_2==l2&&pos_1!=l1)
{
break;
}
if(t1[pos_1]==t2[pos_2])
{
pos_1++;
pos_2++;
}
else pos_2++;
}
if(!flag) cout<<"No"<<endl;
else cout<<"Yes"<<endl;
}
return 0;
}