String subsequence lookup problem, set two pointers, one point to the subsequence, the other point to the sequence to be looked up, find a string to judge once.
1#include <iostream>2#include <string.h>3 using namespacestd;4 Chars[100002];5 Chart[100002];6 intMain () {7 8 while(cin>>s>>t) {9 intlength1=strlen (s);Ten intLength2=strlen (t); One intI=0, j=0; A for(i=0, j=0;i<length1&&j<length2;) { - if(s[i]==T[j]) { -i++; theJ + +; -}Else{ -J + +; - } + } - if(i==length1) +cout<<"Yes"<<Endl; A Else atcout<<"No"<<Endl; - } - return 0; -}
Report:
Time Limit: 1000MS |
|
Memory Limit: 30000K |
Total Submissions: 29592 |
|
Accepted: 12269 |
Description
You are devised a new encryption technique which encodes a message by inserting between its characters randomly generated Strings in a clever. Because of pending patent issues we won't discuss in detail how the strings is generated and inserted into the Origina L message. To validate your method, however, it's necessary to write a program that checks if the message was really encoded in the F Inal string.
Given-strings s and T, you had to decide whether s are a subsequence of T, i.e. if you can remove characters from T su CH, the concatenation of the remaining characters is S.
Input
The input contains several testcases. Each are specified by and strings s, T of alphanumeric ASCII characters separated by whitespace. The length of S and T would no more than 100000.
Output
For each test, the output "Yes", if S is a subsequence of t,otherwise output "No".
Sample Input
Sequence Subsequenceperson Compressionverdi vivavittorioemanuelerediitaliacasedoesmatter CaseDoesMatter
Sample Output
Yesnoyesno
All in All-poj 1936 (substring)