UVa10340.All in All

题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1281

13845990 10340 All in All Accepted C++ 0.026 2014-07-07 15:05:55


All in All

Input: standard input

Output: standard output

Time Limit: 2 seconds

Memory Limit: 32 MB

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 Specification

The input contains several testcases. Each is specified by two strings s, t of alphanumeric ASCII characters separated by whitespace. Input is terminated by EOF.

Output Specification

For each test case output, if s is a subsequence of t.

Sample Input

sequence subsequence
person compression
VERDI vivaVittorioEmanueleReDiItalia
caseDoesMatter CaseDoesMatter

Sample Output

Yes
No
Yes

 No



解题思路:小心特判就好。以前在POJ上写过此题,其中有一组数据是匹配串和模式串相同的情况,要输出Yes。有写简洁的方法并不需要特判。从中也找到了自己的不足,应该多写习题,多多练习,这样才能简化代码。

 1 #include <iostream>
 2 #include <cstring>
 3 #include <cstdio>
 4 #include <cstdlib>
 5 #include <cctype>
 6 #include <cmath>
 7 #include <string>
 8 #include <algorithm>
 9 #include <numeric>
10 using namespace std;
11
12 int main() {
13     string pattern, matcher;
14     while (cin >> pattern >> matcher) {
15         if(pattern == matcher) {
16             cout << "Yes" << endl;
17             continue;
18         }
19
20         if(pattern.size() >= matcher.size()) {
21             cout << "No" << endl;
22             continue;
23         }
24         int cnt = 0; //匹配长度
25
26         for(int i = 0, j = 0; j < matcher.size(); j ++) {
27             if(pattern[i] == matcher[j]) {
28                 i++; cnt++;
29                 if(cnt == pattern.size()) {
30                     break;
31                 }
32             }
33         }
34
35         if(cnt == pattern.size()) {
36             cout << "Yes" << endl;
37         } else {
38             cout << "No" << endl;
39         }
40     }
41     return 0;
42 }

UVa10340.All in All,布布扣,bubuko.com

时间: 2024-10-23 04:11:48

UVa10340.All in All的相关文章

UVa10340

All in All 题意:字符串匹配 #include <stdio.h> #include <string.h> char S[200000]; char P[200000]; int next[200000]; int KMP(int pos, int len1, int len2) { int i = pos, j = 1, k = 0; next[1] = 0; while (j < len1) if (k == 0 || P[k - 1] == P[j - 1])

UVA10340 POJ1936 ZOJ1970 All in All

问题链接:UVA10340 POJ1936 ZOJ1970 All in All.入门练习题,用C语言编写程序. 题意简述:输入两个字符串s和t,看s是否是t的子串.t中的字符可以任意删除,只要顺序匹配字符串就可以. AC的C语言程序如下: /* UVA10340 POJ1936 ZOJ1970 All in All */ #include <stdio.h> #include <string.h> #define MAXN 110000 char s[MAXN], t[MAXN]

UVA10340 All in All子序列

Problem E All in All Input: standard input Output: standard output Time Limit: 2 seconds Memory Limit: 32 MB You have devised a new encryption technique which encodes a message by inserting between its characters randomly generated strings in a cleve

UVA10763:Foreign Exchange&amp;&amp;UVA10340: All in All(水题)

10763:水题不解释直接贴代码. #include <iostream> #include <string.h> #include <stdio.h> #include <algorithm> #include <math.h> #include <queue> #define eps 1e-9 typedef long long ll; using namespace std; int n; int d[500100]; int

UVa10340 All in All (子序列)

输入两个字符串s和t,判断是否可以从t中删除0个或者多个字符(其他字符顺序不变),得到字符串s.例如,abcde可以得到bce,但无法得到cb. Input 输入多组数据 每组一行包含两个字符串s和t,两字符串之间用空格隔开. 字符串长度在100000以内 Output 输出Yes或No Sample Input sequence subsequence person compression VERDI vivaVittorioEmanueleReDiItalia caseDoesMatter

算法竞赛入门经典第二版第三章习题

写这个的原因是看到一位大神的习题答案总结,于是自己心血来潮也想写一个这个,目的主要是督促自己刷题吧,毕竟自己太弱了. 习题3-1 得分 UVa 1585 大致就是设置一个变量记录到当前为止的连续的O的数量,碰到X就变0,水题. #include<stdio.h> #include<ctype.h> #include<string.h> char s[90]; int main(void) { int length,n,sum,num; scanf("%d&qu

All in All,( UVa, 10340 )

题目链接 :https://vjudge.net/problem/UVA-10340 注意数组开辟大小,太小会runtime error: 1 #include<stdio.h> 2 #include<string.h> 3 #define maxn 10000000 4 char s[maxn],t[maxn]; 5 6 int main() 7 { 8 while (scanf("%s %s",s,t)!=EOF) 9 { 10 int j = 0; 11

2019年2月做题记录

UVA10082 (字符串常量水题) UVA272 (字符串替换水题) UVA401 (回文串镜像串水题) UVA340 (模拟题) UVA1583 (打表水题) UVA1584 (暴力) UVA1585 (模拟) UVA1586 (数学) UVA1225 (打表水题) UVA455 (KMP算法) UVA232 (模拟+思维) UVA202 (除法高精度水题) UVA1587 (思维) UVA10340 (模拟,定序求交集) 原文地址:https://www.cnblogs.com/Aya-U