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。有写简洁的方法并不需要特判。从中也找到了自己的不足,应该多写习题,多多练习,这样才能简化代码。
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std; int main() {
string pattern, matcher;
while (cin >> pattern >> matcher) {
if(pattern == matcher) {
cout << "Yes" << endl;
continue;
} if(pattern.size() >= matcher.size()) {
cout << "No" << endl;
continue;
}
int cnt = ; //匹配长度 for(int i = , j = ; j < matcher.size(); j ++) {
if(pattern[i] == matcher[j]) {
i++; cnt++;
if(cnt == pattern.size()) {
break;
}
}
} if(cnt == pattern.size()) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
return ;
}
UVa10340.All in All的更多相关文章
- [刷题]算法竞赛入门经典 3-7/UVa1368 3-8/UVa202 3-9/UVa10340
书上具体所有题目:http://pan.baidu.com/s/1hssH0KO 都是<算法竞赛入门经典(第二版)>的题目,标题上没写(第二版) 题目:算法竞赛入门经典 3-7/UVa13 ...
- UVA10763:Foreign Exchange&&UVA10340: All in All(水题)
10763:水题不解释直接贴代码. #include <iostream> #include <string.h> #include <stdio.h> #incl ...
- 子序列 (All in All,UVa10340)
题目描述:算法竞赛入门经典习题3-9 题目思路:循环匹配 //没有按照原题的输入输出 #include <stdio.h> #include <string.h> #defin ...
- UVA10340 - All in All(紫书习题3.9)
输入两个字符串s和t,判断是否可以从t中删除0个或者多个字符(其他字符顺序不变),得到字符串s.例如,abcde可以得到bce,但无法得到cb. Input 输入多组数据 每组一行包含两个字符串s和t ...
- UVA10340子序列
题意: 给你两个串,问你第二个第一个串是否是第一个串删除0个或多个字母得到的? 思路: 直接模拟就行了,在第二个串中去按顺序更新第一个串的下标,好像没说明白啊,不管了,水题,不 ...
- UVa 10340 子序列
https://vjudge.net/problem/UVA-10340 题意: 输入两个字符串s和t,判断是否可以从t中删除0个或多个字符得到字符串s. 思路: 很水的题... #include&l ...
随机推荐
- Day56
今天干啦啥呢 早上七点起来 天气冷了真起不来啊 再坚持坚持就好了 今天上午九点开始考数据库 我去 大学四年第一次感觉到这样的爽 作弊的爽啊 也没有完全的作弊啦 是开卷考试,反正做的很顺利了. 我和胡 ...
- c指针点滴2之比大小
#include <stdio.h> #include <stdlib.h> void main2() { ]={,,,4.5}; ]; ]; if(p1<p2) { p ...
- AVR32开发环境搭建
下面是搭建AVR32开发环境的过程记录: 1.AVR32的编译环境下载 (到这里下载 as5installer-stable-5.1.208-full.exe) 如果你在安装的过程中碰到如下问题: ...
- Qt使用QGraphicsView实现滑动窗体效果
QGraphicsView用来显示一个滚动视图区的QGraphicsScene内容.QGraphicsScene提供了QGraphicsItem的容器功能.通常与QGraphicsView一起使用来描 ...
- 用SNMP协议实现系统信息监控--CentOS
(1) 安装SNMP客户端以及服务端 安装内容为三项:net-snmp net-snmp-devel net-snmp-utils 安装命令:yum install net-snmp net- ...
- (转)web.config详解之在文件中配置网站默认页面
在<configuration></configuration>中添加下面的配置 <system.webServer> <defaultDocu ...
- 多重和嵌套if
多重if实例: 看例子,内容不解释了! 隐藏行号 复制代码 ? 多重if import java.util.Scanner; public class 多重if{ public static void ...
- 三、服务解析(Resolving Services)
当你完成组件注册,并将组件暴露为适当的服务后你就可以通过容器或者容器的子生命周期域来解析服务(After you have your components registered with approp ...
- (二)原生JS实现 - 事件类方法
事件处理 - 添加事件 var addEventHandler = function (oTarget, sEventType, fnHandler) { if (oTarget.addEventLi ...
- linux下启动和关闭网卡命令及DHCP上网
ifup.ifdown:如果在 /etc/sysconfig/network-scripts里面的ifcfg-ethx等文件存在的话,就可以通过ifdown或ifup来实现网卡的开和关,例如:ifup ...