[POJ1936]All in All

试题描述

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.

输入

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.

输出

For each test case output "Yes", if s is a subsequence of t,otherwise output "No".

输入示例

sequence subsequence
person compression
VERDI vivaVittorioEmanueleReDiItalia
caseDoesMatter CaseDoesMatter

输出示例

Yes
No
Yes
No

数据规模及约定

见“输入

题解

求一个串是不是另一个串的子序列,贪心匹配就行了。

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <stack>
#include <vector>
#include <queue>
#include <cstring>
#include <string>
#include <map>
#include <set>
using namespace std; #define maxn 100010
int n, m;
char S1[maxn], S2[maxn]; int main() {
while(scanf("%s%s", S1 + 1, S2 + 1) != EOF) {
n = strlen(S1 + 1); m = strlen(S2 + 1);
if(n > m){ puts("No"); continue; }
int i = 1, j = 1;
for(; i <= n; i++) {
for(; S1[i] != S2[j] && j <= m; j++) ;
if(j > m) break;
j++;
}
if(i > n) puts("Yes");
else puts("No");
} return 0;
}

[POJ1936]All in All的更多相关文章

  1. POJ-1936 All in All---字符串水题

    题目链接: https://vjudge.net/problem/POJ-1936 题目大意: 给两个字符串,判断是s1是不是s2的子序列 思路: 水 #include<iostream> ...

  2. POJ1035&&POJ3080&&POJ1936

    字符串处理专题,很早就写好了然而忘记写blog了 1035 题意:给你一些单词作为字典.然后让你查找一些单词.对于每个单词,如果在字典中就输出它.否则输出所有它通过删除||增加||替换一个字符能得到的 ...

  3. POJ--1936 All in All(水题,暴力即可)

    All in All Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 30543 Accepted: 12723 Descript ...

  4. poj1936

    非连续子串匹配题,直接模拟 /** \brief poj 1936 * * \param date 2014/8/5 * \param state AC * \return memory 804k t ...

  5. poj1936 假期计划第一水

    All in All Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 29651   Accepted: 12312 Desc ...

  6. poj分类 很好很有层次感。

    初期: 一.基本算法:      (1)枚举. (poj1753,poj2965)      (2)贪心(poj1328,poj2109,poj2586)      (3)递归和分治法.      ( ...

  7. 【转】POJ题目分类推荐 (很好很有层次感)

    OJ上的一些水题(可用来练手和增加自信) (poj3299,poj2159,poj2739,poj1083,poj2262,poj1503,poj3006,poj2255,poj3094)初期: 一. ...

  8. 【转】ACM训练计划

    [转] POJ推荐50题以及ACM训练方案 -- : 转载自 wade_wang 最终编辑 000lzl POJ 推荐50题 第一类 动态规划(至少6题, 和 必做) 和 (可贪心) (稍难) 第二类 ...

  9. POJ 题目分类(转载)

    Log 2016-3-21 网上找的POJ分类,来源已经不清楚了.百度能百度到一大把.贴一份在博客上,鞭策自己刷题,不能偷懒!! 初期: 一.基本算法: (1)枚举. (poj1753,poj2965 ...

随机推荐

  1. Moqui学习之数据与资源

    资源位置: 资源门面位置的字符串类似于URL的构成方式:协议,主机,可选端口和文件名.它支持标准的java URL协议(http https ftp jar file).同样也支持一些扩展的协议: c ...

  2. 一款轻量级移动web开发框架

    本帖最后由 yangzhu230 于 2013-9-11 00:39 编辑 如果我说要推荐zepto你肯定说“切,这地球人都知道,又一个标题党” 不卖关子,开门见山我推荐的是[百度]的GMU GMU是 ...

  3. javascript 重难点(原型链 this) 理解总有一个过程,不要急,循序渐进!

    开始补充: 1. 将函数定义作为对象的属性,称之为对象方法.2. this的指向是由它所在函数调用的上下文决定的(语境),而不是由它所在函数定义的上下文决定的.3. 因为当一个函数作为函数而不是方法来 ...

  4. java核心数据结构总结

    JDK提供了一组主要的数据结构的实现,如List.Set.Map等常用结构,这些结构都继承自java.util.collection接口. List接口 List有三种不同的实现,ArrayList和 ...

  5. myeclipse自动import

    不管包什么的 直接把代码全写出来 再按 ctrl + shift +o 这是自动导包的 前提是你写的代码是正确的

  6. java_WEB开发 防刷新

    客户端处理: 面对客户端我们可以使用Javascript脚本来解决,如下 1.重复刷新.重复提交 Ways One:设置一个变量,只允许提交一次. <script language=" ...

  7. Kettle_使用Pan.bat执行转换、Kitchen.bat执行作业

    参考资料:http://www.cnblogs.com/wxjnew/p/3620792.html 注意:使用bat文件执行速度比执行在spoon.bat中执行慢很多 一.使用Pan.bat执行转换 ...

  8. 【前端】Sublime text3 插件LiveReload 实现实时预览

    1.首先要安装插件LiveReload Sublime text3. 菜单 preferences->packages control,输入install.. 回车,输入LiveReload回车 ...

  9. url的编码问题

    JQuery中 编码 var url = 'folder/index.html?param=#23dd&noob=yes'; var encodedUrl = encodeURICompone ...

  10. 人工蜂群算法-python实现

    ABSIndividual.py import numpy as np import ObjFunction class ABSIndividual: ''' individual of artifi ...