前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >POJ--1936 All in All(水题,暴力即可)

POJ--1936 All in All(水题,暴力即可)

作者头像
ShenduCC
发布2018-04-25 17:33:28
6260
发布2018-04-25 17:33:28
举报
文章被收录于专栏:算法修养算法修养

All in All Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 30543 Accepted: 12723 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

代码语言:javascript
复制
#include <iostream>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <stdlib.h>

using namespace std;
#define MAX 100000
char a[MAX+5];
char b[MAX+5];
int main()
{
    int pos;
    bool res;
    while(scanf("%s%s",&a,&b)!=EOF)
    {
        pos=-1;
        res=true;
        int tag;
        int len1=strlen(a);
        int len2=strlen(b);
        for(int i=0;i<len1;i++)
        {
            tag=0;
            for(int j=0;j<len2;j++)
            {
                if(a[i]==b[j])
                {
                    if(j>pos)
                    {
                       tag=1;
                       pos=j;
                       break;
                    }
                }
            }
            if(tag==0)
                res=false;
        }
        if(res==true)
            printf("Yes\n");
        else
            printf("No\n");
    }
}
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2016-01-04 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档