字符串子序列查找问题,设置两个指针,一个指向子序列,另一个指向待查找的序列,查找个字符串一次即可判断。
 
 #include <iostream>
#include <string.h>
using namespace std;
char s[];
char t[];
int main() { while(cin>>s>>t){
int length1=strlen(s);
int length2=strlen(t);
int i=,j=;
for(i=,j=;i<length1&&j<length2;){
if(s[i]==t[j]){
i++;
j++;
}else{
j++;
}
}
if(i==length1)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}
return ;
}

附:

Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 29592   Accepted: 12269

Description

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

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.

Output

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

Sample Input

sequence subsequence
person compression
VERDI vivaVittorioEmanueleReDiItalia
caseDoesMatter CaseDoesMatter

Sample Output

Yes
No
Yes
No

All in All - poj 1936 (子串)的更多相关文章

  1. POJ 1936 All in All(模拟)

    All in All 题目链接:http://poj.org/problem?id=1936 题目大意:判断从字符串s2中能否找到子串s1.字符串长度为10W. Sample Input sequen ...

  2. POJ 1936 All in All 匹配, 水题 难度:0

    题目 http://poj.org/problem?id=1936 题意 多组数据,每组数据有两个字符串A,B,求A是否是B的子串.(注意是子串,也就是不必在B中连续) 思路 设置计数器cnt为当前已 ...

  3. OpenJudge/Poj 1936 All in All

    1.链接地址: http://poj.org/problem?id=1936 http://bailian.openjudge.cn/practice/1936 2.题目: All in All Ti ...

  4. poj 1936 All in All(水题)

    题目链接:http://poj.org/problem?id=1936 思路分析:字符串子序列查找问题,设置两个指针,一个指向子序列,另一个指向待查找的序列,查找个字符串一次即可判断.算法时间复杂度O ...

  5. poj 1936 All in All

    All in All Time Limit: 1000 MS Memory Limit: 30000 KB 64-bit integer IO format: %I64d , %I64u   Java ...

  6. Poj 1936,3302 Subsequence(LCS)

    一.Description(3302) Given a string s of length n, a subsequence of it, is defined as another string ...

  7. POJ 1936

    #include<iostream> #include<string> using namespace std; int main() { //freopen("ac ...

  8. 简单的字符串比较题 POJ 1936

    Description You have devised a new encryption technique which encodes a message by inserting between ...

  9. POJ 1936 All in All(串)

    All in All Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 27537 Accepted: 11274 Descript ...

随机推荐

  1. oracle审计AUD$过大导致的数据库登录异常

      今天,省分技术人员反映数据库登录异常. 查询oerr,发现该错误是一般性提示,可能导致的原因有数据库未注册.本地文件配置问题等.由于平时连接并没有问题,是突发情况,所以排除了配置问题. 远程登录查 ...

  2. 第三天 ThinkPHP手把手高速拼接站点(三)

    6月1日,小雨." 梅子金黄杏子肥,麦花雪白菜花稀. 日长篱落无人过,唯有蜻蜓蛱蝶飞." 七.MVC模式 ThinkPHP的MVC开发机制例如以下: M  Model层    模型 ...

  3. 代码这样写更优雅(Python 版)(转载)

    转载:https://mp.weixin.qq.com/s?timestamp=1498528588&src=3&ver=1&signature=DfFeOFPXy44ObCM ...

  4. LINUX 和WINDOWS下的自动登录小脚本

    每天上班第一件事,就是连接公司LAB里面的机器,但首先要过一个防火墙,每次输用户名密码是很累人的事, 以下是两个脚本,可以放在启动项中,开机便自动登录 WINDOWS: @echo off ipcon ...

  5. Spark createDirectStream 维护 Kafka offset(Scala)

    createDirectStream方式需要自己维护offset,使程序可以实现中断后从中断处继续消费数据. KafkaManager.scala import kafka.common.TopicA ...

  6. uva 10934 装满水的气球

    题意和思路见: http://blog.csdn.net/shuangde800/article/details/11273123 我的想法: 首先问题转化一下 将问题转化成:定义f[i][j] 表示 ...

  7. Jquery获取当前行的数据

    取表格当前行数据js代码: Java代码 $(function() { $(".myclass").each(function(){     var tmp=$(this).chi ...

  8. git学习——分支

    分支 创建分支:git branch 如:git branch testing Git通过HEAD指针知道用户是在哪一个分支上工作. 切换分支用git checkout命令,注意:可以用git sta ...

  9. 倍福TwinCAT(贝福Beckhoff)应用教程12.3 TwinCAT控制松下伺服 NC进阶

    在前面一节,我们简单介绍了通过PLC+HMI实现完整控制松下伺服的上使能-运动,采集位置,速度等功能,这里我们会大量简化用到的贝福功能块(为了更加实用).首先依然是对单个轴的封装,我们之前的做法,例如 ...

  10. MPTCP 源码分析(三) 子路径选择

    简述:      支持MPTCP的链路中存在多条子路径,因此在发送数据的时候需要选择最优路径来进行操作. MPTCP利用内核通知链对MPTCP中各子路径进行增加路径.删除路径.修改路径优先级的操作.M ...