[POJ] 3302 Subsequence
来源:互联网 发布:格式化硬盘还能恢复数据吗 编辑:程序博客网 时间:2024/05/17 07:50
给定两个字符串,要求判断后一个字符串是否是前一个字符串或者前一个字符串的反串经过裁剪得到的子字符串。
题目不难,正向比较一次,反向比较一次即可。
//By:一只大幽灵//Time:2012/4/11#include <iostream>#include <cstring>using namespace std;class Subsequence {public: void in(); bool sub();private: char s1[101], s2[101];};bool Subsequence::sub() { int len1 = strlen(s1); int len2 = strlen(s2); int s = 0, t = 0; int f = 0; if (len2 > len1)return false; for (int i = 0; i < len2; i++) { f = 0; for (int j = t; j < len1; j++) { if (s1[j] == s2[i]) { s++; t = j + 1; f = 1; break; } } if (s == len2)return true; else if (f == 0)break; } s = 0; t = 0; for (int i = len2 - 1; i >= 0; i--) { f = 0; for (int j = t; j < len1; j++) { if (s1[j] == s2[i]) { s++; t = j + 1; f = 1; break; } } if (s == len2)return true; else if (f == 0)break; } return false;}void Subsequence::in() { int n; cin >> n; while (n--) { cin >> s1 >> s2; if (sub())cout << "YES" << endl; else cout << "NO" << endl; }}int main() { Subsequence s; s.in(); return 0;}
- [POJ] 3302 Subsequence
- POJ 3302 Subsequence G++
- POJ 3302 Subsequence 解题报告
- Poj 1936,3302 Subsequence(LCS)
- poj Subsequence
- Subsequence POJ
- poj Subsequence
- POJ:Subsequence
- POJ 3302 Subsequence(简单题)
- POJ 3302 Subsequence 已被翻译
- Common Subsequence--poj--1458
- poj 1458 Common Subsequence
- poj 3061 Subsequence
- poj 1458 Common Subsequence
- Common Subsequence poj 1548
- Poj 1458 Common Subsequence
- POJ 1458 Common Subsequence
- poj 1458 Common Subsequence
- Per Pixel Lighting [Part 3]
- mysql 自动注册 ODBC
- wincap的学习总结01
- epoll服务器示例, 监听5000个端口, 使用线程池
- 通过Eclipse3.1以上启动Tomcat访问不到tomcat管理界面的问题
- [POJ] 3302 Subsequence
- Per Pixel Lighting [Part 4]
- 普瑞玛法则
- span层在DIV中设置高度
- epoll多线程
- 用Eclipse 创建web项目
- Per Pixel Lighting [Part 5]
- Per Pixel Lighting [Part 6]
- Per Pixel Lighting [Part 7]