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 ...
随机推荐
- 一、mysql分表简单介绍
一.Mysql分表的原因 1.当一张的数据达到几百万时,你查询一次所花的时间会变多,如果有联合查询的话,我想有可能会死在那儿了. 分表的目的就在于此,减小数据库的负担,缩短查询时间. 2.mysql中 ...
- 页面onclick()中传值问题
html中onclick()里面传变量到javascript中的问题,小小的记录下: 传变量的话一定要加 '' <span onclick="sellGoods('${session ...
- HTTP协议具体解释
HTTP是一个属于应用层的面向对象的协议.因为其简捷.高速的方式.适用于分布式超媒体信息系统. 它于1990年提出,经过几年的使用与发展,得到不断地完好和扩展.眼下在WWW中使用的是HTTP/1.0的 ...
- Windows下命令行直接编译程序
D:\> cl hello.cpp Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8804 for 80x86 Cop ...
- SWTBOK測试实践系列(4) -- 软件測试技术的黑白之道
白盒測试和黑盒測试往往是项目中最受争议的两种測试类型,每一个人偏爱各不同.现实生活中行业人员大多喜欢白盒測试而忽视黑盒測试,那么项目中又应该怎样平衡这两类測试呢?我们先来看两个案例. 案例一: 某移动 ...
- Qt使用QGraphicsView实现滑动窗体效果
QGraphicsView用来显示一个滚动视图区的QGraphicsScene内容.QGraphicsScene提供了QGraphicsItem的容器功能.通常与QGraphicsView一起使用来描 ...
- (转)Ajax的原理和应用
1.ajax技术的背景 不可否认,ajax技术的流行得益于google的大力推广,正是由于google earth.google suggest以及gmail等对ajax技术的广泛应用,催生了ajax ...
- Objective-C中的单例模式(工具类)
单例是iOS开发中经常会用到的一种设计模式,顾名思义,即创建一个类,该类在整个程序的生命周期中只有一个实例对象,无论是通过new,alloc init,copy等方法创建,或者创建多少个对象,自始至终 ...
- BZOJ4195 NOI2015 程序自动分析
4195: [Noi2015]程序自动分析 Time Limit: 10 Sec Memory Limit: 512 MB Description 在实现程序自动分析的过程中,常常需要判定一些约束条件 ...
- hdu1406
一道很水很水的题!!!!!!!!!! #include<iostream> using namespace std; int main(){ int num1,num2,i,k,j,sum ...