POJ 1936.All in All

All in All
Time Limit:1000MS     Memory Limit:30000KB     64bit IO Format:%I64d & %I64u

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. 

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

 

应该算是水题吧~

用两个变量记录指向s、t字符串的位置。

如果相等,则把指向s的+1

看循环完s是否在最后即可

 

 

AC代码:GitHub

 

 1 /*
 2 By:OhYee
 3 Github:OhYee
 4 HomePage:http://www.oyohyee.com
 5 Email:oyohyee@oyohyee.com
 6 Blog:http://www.cnblogs.com/ohyee/
 7 
 8 かしこいかわいい?
 9 エリーチカ!
10 要写出来Хорошо的代码哦~
11 */
12 
13 #include <cstdio>
14 #include <algorithm>
15 #include <cstring>
16 #include <cmath>
17 #include <string>
18 #include <iostream>
19 #include <vector>
20 #include <list>
21 #include <queue>
22 #include <stack>
23 #include <map>
24 using namespace std;
25 
26 //DEBUG MODE
27 #define debug 0
28 
29 //循环
30 #define REP(n) for(int o=0;o<n;o++)
31 
32 const int maxn = 100005;
33 
34 bool Do() {
35     char s[maxn],t[maxn];
36     if(scanf("%s%s",s,t) == EOF)
37         return false;
38     
39     int t_len = strlen(t);
40     int s_len = strlen(s);
41 
42     int it = 0;
43     for(int i = 0;i < t_len;i++) {
44         if(s[it] == t[i])
45             it++;
46         if(it == s_len)
47             break;
48     }
49 
50     printf("%s\n",(it == s_len) ? "Yes" : "No");
51 
52     return true;
53 }
54 
55 int main() {
56     while(Do());
57     return 0;
58 }

 

posted @ 2016-05-08 23:36  OhYee  阅读(175)  评论(0编辑  收藏  举报