POJ 1936

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
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<string.h>
typedef long long ll;
#define N 100005
using namespace std;
char str1[N];
char str2[N];
int main()
{
    int len1,len2;
    int i,j;
    while(cin>>str1>>str2)
    {
        len1=strlen(str1);
        len2=strlen(str2);
        int p=0;
        int t=0;
        for(i=0;i<len1;i++)
        {
            for(j=p;j<len2;j++)
            {
                if(str1[i]==str2[j])
                {
                    t++;
                    p=j+1;
                    break;
                }
            }
            if(j>=len2)
                break;
        }
        if(t==len1)
            printf("Yes\n");
        else
            printf("No\n");
    }
}
时间: 2024-11-16 02:51:43

POJ 1936的相关文章

POJ 1936.All in All

All in All Time Limit:1000MS     Memory Limit:30000KB     64bit IO Format:%I64d & %I64u Submit Status Practice POJ 1936 Description You have devised a new encryption technique which encodes a message by inserting between its characters randomly gener

[ACM] POJ 1936 All in All (查找,一个串是否在另一个串中)

All in All Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 27521   Accepted: 11266 Description You have devised a new encryption technique which encodes a message by inserting between its characters randomly generated strings in a clever

POJ 1936 All in All 题解

寻找一个串是否是另外一个字符串的子串序列. 可以想象主串是一连发子弹,而需要查找的子串是一队敌人,然后主串的字符是目标,把主串的所有子弹打完,是否能把子串的所有敌人消灭掉. 很简单的题目. #include <stdio.h> const int MAX_N = 100001; char seq[MAX_N], subSeq[MAX_N]; int main() { while (~scanf("%s %s", subSeq, seq)) { char *s = seq,

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

题目 http://poj.org/problem?id=1936 题意 多组数据,每组数据有两个字符串A,B,求A是否是B的子串.(注意是子串,也就是不必在B中连续) 思路 设置计数器cnt为当前已匹配A的长度,明显在扫描B的过程中只需要记住cnt这一个状态. 扫描B,每次与A[cnt]匹配就将计数器增加1,cnt与A的长度一致时A就是B的子串. 感想 这道题也许可以用更复杂的方法. 代码 1 #include <cstdio> 2 #include <cstring> 3 #i

All in All - poj 1936 (子串)

字符串子序列查找问题,设置两个指针,一个指向子序列,另一个指向待查找的序列,查找个字符串一次即可判断. 1 #include <iostream> 2 #include <string.h> 3 using namespace std; 4 char s[100002]; 5 char t[100002]; 6 int main() { 7 8 while(cin>>s>>t){ 9 int length1=strlen(s); 10 int length2

POJ 1936 All in All(串)

All in All Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 27537 Accepted: 11274 Description You have devised a new encryption technique which encodes a message by inserting between its characters randomly generated strings in a clever way

POJ 1936 All in All(string)

All in All Time Limit: 1000MS   Memory Limit: 30000K       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 issue

zoj1970||poj 1936 All in All

注意细节,一直把Yes,写成YES,找错误找了老半天都找不出来.... 代码如下: #include<stdio.h> #include<string.h> int main() { char s[100005],t[100005]; int m,i,j,n; while(scanf("%s%s",s,t)!=EOF) { m=strlen(t); n=strlen(s); i=0; for(j=0;j<m;j++)//关键步骤,只判定b数组是否到头,复杂

POJ题目分类推荐 (很好很有层次感)

著名题单,最初来源不详.直接来源:http://blog.csdn.net/a1dark/article/details/11714009 OJ上的一些水题(可用来练手和增加自信) (POJ 3299,POJ 2159,POJ 2739,POJ 1083,POJ 2262,POJ 1503,POJ 3006,POJ 2255,POJ 3094) 初期: 一.基本算法: 枚举. (POJ 1753,POJ 2965) 贪心(POJ 1328,POJ 2109,POJ 2586) 递归和分治法. 递