All in all
Time limit:1000 ms |
|
Memory limit:30000 K |
Total submissions:25558 |
|
Accepted:10280 |
Description
You have devised a new encryption technique which encodes a message by inserting between its characters generated strings in a clever way. Because of pending patent issues we will not discuss in detail how 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 ".
Sample Input
sequence subsequenceperson compressionVERDI vivaVittorioEmanueleReDiItaliacaseDoesMatter CaseDoesMatter
Sample output
YesNoYesNo
Source
Ulm Local 2002
It is to give two strings so that you can find the first one in the second string, but it can be: insert several letters into 1st strings, this situation is also found. Find output yes,
No output found.
Analysis: it is easy to think that the length of the first string must be smaller than that of the second string. In fact, it is necessary to judge. If the first string is greater than the second string, then string 2 will not contain string 1. If the length of two strings
Equal, directly compare whether it is the same string. If yes is output, otherwise no is output. The rest is that the length of string 1 is smaller than string 2. In this case, only one for loop is required. I = 0, from str1 [0]
At the beginning, if equal characters are found, I ++. If String 2 has been found, and no character in string 1 has been found in the order of appearance, no is output.
Feeling: 1. I started to understand the question wrong. I thought that the interval letter is not counted, that is, I had to find string 1 in string 2.
2. Later I ignored the string length judgment.
3. In fact, as long as the letters in string 1 are found in the order of occurrence in string 2, you can.
I think it is just a question of water ~~~~~~~~!!!!!!!
Code:
#include<cstdio>#include<iostream>#include<cstring>using namespace std;char str1[100010],str2[100010];int main(){ while(scanf("%s %s",&str1,&str2)!=EOF) { bool flag=false; int len1=strlen(str1),len2=strlen(str2); int i=0,j=0; if(len1 > len2) { puts("No"); } else if(len1 == len2) { if(strcmp(str1,str2) == 0) puts("Yes"); else puts("No"); } else { int flag=0; int i=0,j; for(j=0;str2[j];j++) { if(str2[j]==str1[i]) i++; if(i==len1) { flag=1; break; } } if(flag) puts("Yes"); else puts("No"); } } return 0;}
11945788 |
Fukan |
1936 |
Accepted |
236 K |
0 ms |
C ++ |
1027b |
2013-08-08 21:18:50 |