POJ 1936.All in All

All in All

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

Submit Status Practice POJ 1936

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:[email protected]
 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 }
时间: 2024-08-08 09:20:43

POJ 1936.All in All的相关文章

[ACM] POJ 1936 All in All (查找,一个串是否在另一个串中)

All in All Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 27521   Accepted: 11266 Description You have devised a new encryption technique which encodes a message by inserting between its characters randomly generated strings in a clever

POJ 1936 All in All 题解

寻找一个串是否是另外一个字符串的子串序列. 可以想象主串是一连发子弹,而需要查找的子串是一队敌人,然后主串的字符是目标,把主串的所有子弹打完,是否能把子串的所有敌人消灭掉. 很简单的题目. #include <stdio.h> const int MAX_N = 100001; char seq[MAX_N], subSeq[MAX_N]; int main() { while (~scanf("%s %s", subSeq, seq)) { char *s = seq,

POJ 1936 All in All 匹配, 水题 难度:0

题目 http://poj.org/problem?id=1936 题意 多组数据,每组数据有两个字符串A,B,求A是否是B的子串.(注意是子串,也就是不必在B中连续) 思路 设置计数器cnt为当前已匹配A的长度,明显在扫描B的过程中只需要记住cnt这一个状态. 扫描B,每次与A[cnt]匹配就将计数器增加1,cnt与A的长度一致时A就是B的子串. 感想 这道题也许可以用更复杂的方法. 代码 1 #include <cstdio> 2 #include <cstring> 3 #i

POJ 1936

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 generat

All in All - poj 1936 (子串)

字符串子序列查找问题,设置两个指针,一个指向子序列,另一个指向待查找的序列,查找个字符串一次即可判断. 1 #include <iostream> 2 #include <string.h> 3 using namespace std; 4 char s[100002]; 5 char t[100002]; 6 int main() { 7 8 while(cin>>s>>t){ 9 int length1=strlen(s); 10 int length2

POJ 1936 All in All(串)

All in All Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 27537 Accepted: 11274 Description You have devised a new encryption technique which encodes a message by inserting between its characters randomly generated strings in a clever way

POJ 1936 All in All(string)

All in All Time Limit: 1000MS   Memory Limit: 30000K       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 issue

zoj1970||poj 1936 All in All

注意细节,一直把Yes,写成YES,找错误找了老半天都找不出来.... 代码如下: #include<stdio.h> #include<string.h> int main() { char s[100005],t[100005]; int m,i,j,n; while(scanf("%s%s",s,t)!=EOF) { m=strlen(t); n=strlen(s); i=0; for(j=0;j<m;j++)//关键步骤,只判定b数组是否到头,复杂

POJ题目分类推荐 (很好很有层次感)

著名题单,最初来源不详.直接来源:http://blog.csdn.net/a1dark/article/details/11714009 OJ上的一些水题(可用来练手和增加自信) (POJ 3299,POJ 2159,POJ 2739,POJ 1083,POJ 2262,POJ 1503,POJ 3006,POJ 2255,POJ 3094) 初期: 一.基本算法: 枚举. (POJ 1753,POJ 2965) 贪心(POJ 1328,POJ 2109,POJ 2586) 递归和分治法. 递