All in All - poj 1936 (子串)
2015-08-01 10:20
260 查看
字符串子序列查找问题,设置两个指针,一个指向子序列,另一个指向待查找的序列,查找个字符串一次即可判断。
附:
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
Sample Output
#include <iostream> #include <string.h> using namespace std; char s[100002]; char t[100002]; int main() { while(cin>>s>>t){ int length1=strlen(s); int length2=strlen(t); int i=0,j=0; for(i=0,j=0;i<length1&&j<length2;){ if(s[i]==t[j]){ i++; j++; }else{ j++; } } if(i==length1) cout<<"Yes"<<endl; else cout<<"No"<<endl; } return 0; }
附:
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 29592 | Accepted: 12269 |
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
相关文章推荐
- STM32中GPIO口的8种模式
- 新的公司,新的技术
- 值语义与对象语义
- CABasicAnimation animationWithKeyPath
- 万丈高楼从0开始。
- 最短路
- 杂项设备的学习
- 安卓设备适配终极杀器-谷歌百分比布局库的使用
- 双系统IOS\windows7 换成Windows10后果
- hdu3047 Zjnu Stadium && HDU 3038 How Many Answers Are Wrong (带权并查集)
- MySQL优化
- 观CSDN网站小Bug有感
- JSP和servlet工作原理
- EventBus源码学习之单实例
- Swift2学习笔记(1)
- 设计模式(5):建造者模式
- 转:OSAL多任务资源分配机制
- 复制导致两台虚拟机ping不通
- 52 - 构建乘积数组
- hdu1087 动态规划