题目链接: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的更多相关文章

  1. [刷题]算法竞赛入门经典 3-7/UVa1368 3-8/UVa202 3-9/UVa10340

    书上具体所有题目:http://pan.baidu.com/s/1hssH0KO 都是<算法竞赛入门经典(第二版)>的题目,标题上没写(第二版) 题目:算法竞赛入门经典 3-7/UVa13 ...

  2. UVA10763:Foreign Exchange&&UVA10340: All in All(水题)

    10763:水题不解释直接贴代码. #include <iostream> #include <string.h> #include <stdio.h> #incl ...

  3. 子序列 (All in All,UVa10340)

    题目描述:算法竞赛入门经典习题3-9 题目思路:循环匹配 //没有按照原题的输入输出 #include <stdio.h> #include <string.h> #defin ...

  4. UVA10340 - All in All(紫书习题3.9)

    输入两个字符串s和t,判断是否可以从t中删除0个或者多个字符(其他字符顺序不变),得到字符串s.例如,abcde可以得到bce,但无法得到cb. Input 输入多组数据 每组一行包含两个字符串s和t ...

  5. UVA10340子序列

    题意:       给你两个串,问你第二个第一个串是否是第一个串删除0个或多个字母得到的? 思路:       直接模拟就行了,在第二个串中去按顺序更新第一个串的下标,好像没说明白啊,不管了,水题,不 ...

  6. UVa 10340 子序列

    https://vjudge.net/problem/UVA-10340 题意: 输入两个字符串s和t,判断是否可以从t中删除0个或多个字符得到字符串s. 思路: 很水的题... #include&l ...

随机推荐

  1. c语言枚举型常量

    #include <stdio.h> //代表百度工程师的级别 enum level { //如果没有指定初始的值 那么c语言会自动分配一个编号 整数编号 T14=,T13=,T12=,T ...

  2. 第30讲 UI组件之 GridView组件

    第30讲 UI组件之 GridView组件 1.网格布局组件GridView GridView是一个ViewGroup(布局控件),可使用表格的方式显示组件,可滚动的控件.一般用于显示多张图片,比如实 ...

  3. Ubuntu中设置静态IP和DNS(转载)

    原文地址:http://blog.sina.com.cn/s/blog_669421480102v3bb.html VMware 中使用网络,对虚拟机设置静态IP:在Ubuntu中设置静态IP共两步: ...

  4. iOS9适配+warning消除

    最近做了iOS 9的适配,程序出现大量警告也做了些处理,写出来分先给大家. 一.iOS 9适配 问题一: <Error>: CGContextSaveGState: invalid con ...

  5. IIS 7 支持10万并发请求

    原文链接:http://www.cnblogs.com/dudu/archive/2009/11/10/1600062.html 今天下午17点左右,博客园博客站点出现这样的错误信息: Error S ...

  6. jquery的Post方法$.post()

    $.post是jquery自带的一个方法,使用前需要引入jquery.js 语法:$.post(url,data,callback,type); url(必须):发送请求的地址,String类型 da ...

  7. poj 3104 二分

    Drying Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 12568   Accepted: 3243 Descripti ...

  8. BestCoder Round #36 (hdu5200)Strange Class(离线)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Trees Time Limit: 2000/1000 MS (Java/Othe ...

  9. Protobuf, understand the hood

    proto文件定义 package lm; message Foo{ required int32 id = 1; } message Bar{ required int32 id = 1 [defa ...

  10. django post方法不能提交

    def login(request): if request.method == 'GET': c = {} c.update(csrf(request)) return render_to_resp ...