POJ 1936 All in All

简介: DescriptionYou have devised a new encryption technique which encodes a message by inserting between its characters randomly generated strings in a clever way.

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
题目要求就是在s2中找字串s1!

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;
char a[100005],b[100005];
int main()
{
    while(~scanf("%s",a)){
        scanf("%s",b);
        int a_length = strlen(a);
        int b_length = strlen(b);
        int a1,b1=0;
        int i;
        for(i=0;i<a_length;i++){
                bool flag=false;
            for(int j=b1;j<b_length;j++){
                if(a[i]==b[j]){
                    b1=j+1;
                    flag=true;
                    break;
                }
            }
            if(!flag)
                break;
        }
        if(i==a_length)
            printf("Yes\n");
        else
            printf("No\n");
    }
    return 0;
}
目录
相关文章
|
机器学习/深度学习
|
SDN
poj 2886 Who Gets the Most Candies?
点击打开poj 2886 思路: 求因子数+单点更新 分析: 1 题目的意思是有n个人构成一个环,刚开始是第k个人先出来。每个人有一个名字和数值A,如果A为正数,那么下一个出去的人是他左边的第A个人,如果是负数那么出去的将是右边的第A个人 2 这么我们要注意一下,因为n个人是围城一圈,那么左边就是顺时针方向,右边就是逆时针方向 3 那么我们就可以来推没一次出去的人的在剩下中是第几个。
770 0
poj 2912 Rochambeau
点击打开链接poj 2912 思路: 带权并查集 分析: 1 有n个小孩玩游戏,里面有一个入是裁判,剩下的人分为三组。现在我们既不知道裁判是谁也不知道分组的情况。
935 0
poj 2337 Catenyms
点击打开链接poj2377 思路: 并查集+排序+欧拉道路 分析: 1 题目要求的是,是否可以组成欧拉道路并且输出字典序最小的方案 2 和别的题目不一样的是这一题的输出是最小的字典序,所以这里面是一个难点,那么我们应该怎么做呢?其实我们只要对输入的n个单词进行从小到达排序即可 3 然后我们先去判断该有向图是否是单连通的 4 我们去判断是否最多只有两个点的入度不等与出度,其余所有点的出度等于入度 5 如果都满足的话,进行dfs。
844 0
poj 2528 Mayor's posters
点击打开链接poj2528 思路:离散化+线段树成段更新 分析: 1 首先这一题的数据是错误的,这题的区间的最大值为10000000,如果我们按照正常的线段树的思路去做的话肯定是会超内存和超时的。
1068 0