poj 1936 All in All 简单的字符串匹配
2013-12-17 13:14
204 查看
All in All
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
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 26339 | Accepted: 10691 |
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 Source Code Problem: 1936 Memory: 560K Time: 0MS Language: GCC Result: Accepted Source Code #include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX 100005 int SolveCase_1(char *s, char *t) { char *temp_s = s; int count_s=0 ,number, i, j; while(*temp_s != '\0') { count_s++; temp_s ++; } for(i=0, j=0, number=0; i < MAX; i++) { if(t[j]=='\0' || s[i] =='\0') break; if(t[j]==s[i]){ number++; j++; }else{ number=0; j++; } } if(number == count_s) return 1; return 0; } int SolveCase_2(char *s, char *t) { int count_t = 0; char *temp_t = t; char *temp_s = s; int count_s =0, i, j; while(*temp_t != '\0') { temp_t ++; count_t ++; } while(*temp_s != '\0') { temp_s ++; count_s ++; } for(i = 0,j = 0; i < count_t; i++) { if(s[j] == '\0' || t[i]=='\0') break; if(s[j]==t[i]) j++; if(j==count_s) break; } if(j==count_s) return 1; return 0; } int main() { // freopen("i.txt","r",stdin); char s[MAX], t[MAX]; memset(s, '\0', sizeof(s)); memset(t, '\0', sizeof(t)); while(scanf("%s%s", s, t) !=EOF) { if(SolveCase_1(s, t)!=1){ if(SolveCase_2(s, t)!=1) printf("No\n"); else printf("Yes\n"); }else printf("Yes\n"); memset(s, '\0', sizeof(s)); memset(t, '\0', sizeof(t)); } return 0; }
相关文章推荐
- 简单的字符串匹配 poj1936
- POJ 1936(字符串匹配) 解题报告
- POJ 1936(字符串匹配) 解题报告
- POJ 1936(字符串匹配)
- POJ 1936 All in All 字符串匹配
- POJ 1035 Spell checker 简单字符串匹配
- POJ 1936 All in All ---- 串匹配
- POJ 1936 All in all 简单字符串比较
- POJ 1936 All in all 简单字符串比较
- [POJ](1936)All in All ---字符串匹配(串)
- poj1035 简单字符串匹配
- POJ 1936 All in All(简单的字符串的字符列)
- poj 3080 Blue Jeans kmp 字符串匹配
- poj 3080 Blue Jeans 字符串匹配
- HDU 1686 Oulipo , 同 POJ 3461 Oulipo (字符串匹配,KMP)
- poj 1936 简单的寻找子串
- 字符串匹配算法——KMP算法简单解释
- 字符串匹配的KMP算法(简单易懂)
- UVA-1588-Kickdown:简单字符串匹配
- 几种字符串匹配算法性能简单实验对比