描述

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.

输入

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.

输出

For each test case output "Yes", if s is a subsequence of t,otherwise output "No".

样例输入

sequence subsequence
person compression
VERDI vivaVittorioEmanueleReDiItalia
caseDoesMatter CaseDoesMatter

样例输出

Yes
No
Yes
No

解法:

#include<stdio.h>
#include<string.h>
#define MAXN 100000
char first[MAXN+];
char second[MAXN+];
int main(void)
{
int first_len, second_len, i, j;
bool find;
while(scanf("%s%s", first, second) != EOF)
{
first_len = strlen(first);
second_len = strlen(second);
if(first_len > second_len)
printf("No\n");
else
{
j = ;
for(i = ; i < first_len; i++)
{
find = false; // 主要用来应付最后一个字符
for(; j < second_len; j++)
{
if(second[j] == first[i])
{
j++;
find = true;
break;
}
} if(j == second_len)
break;
}
if(find && i >= first_len-)
printf("Yes\n");
else
printf("No\n");
}
} return ;
}

开始的时候,Yes 和No 都写成了大写,一直WA,郁闷了个数小时。。。
更简洁的写法:

#include<stdio.h>
#include<string.h>
#define MAXN 100000
char first[MAXN+];
char second[MAXN+];
int main(void)
{
int i, j, first_len, second_len; while(scanf("%s%s", first, second) != EOF)
{
first_len = strlen(first);
second_len = strlen(second);
i = j = ;
while(i < first_len && j < second_len)
{
if(first[i] == second[j])
{
i++;
j++;
}
else
j++; } if(i == first_len)
printf("Yes\n");
else
printf("No\n");
} return ;
}

OpenJudge_1936:All in All的更多相关文章

随机推荐

  1. hibernate 注释多表 级联操作

    一对多模型(单向) 说明: 一个客户对应多个地址,通过客户可以获得该客户的多个地址的信息.客户和地址是一对多的关系,并且客户与地址是单向关联的关系. 映射策略 # 外键关联:两个表的关系定义在一个表中 ...

  2. Leetcode543.Diameter of Binary Tree二叉树的直径

    给定一棵二叉树,你需要计算它的直径长度.一棵二叉树的直径长度是任意两个结点路径长度中的最大值.这条路径可能穿过根结点. 示例 : 给定二叉树 1 / \ 2    3 / \ 4  5 返回 3, 它 ...

  3. ESB介绍

    通过使用ESB,可以在几乎不更改代码的情况下,以一种无缝的非侵入方式使企业已有的系统具有全新的服务接口,并能够在部署环境中支持任何标准.更重要的是,充当“缓冲器”的ESB(负责在诸多服务之间转换业务逻 ...

  4. [转]json对象详解

    json(javascript object notation)全称是javascript对象表示法,它是一种数据交换的文本格式,而不是一种编程语言,用于读取结构化数据.2001年由Douglas C ...

  5. Linux 下用Win共享

    让win能访问到 linux 的smb 共享: linux 安装 samba: apt-get install samba #然后 vim /etc/samba/smb.conf #找到securit ...

  6. 关于 matplotlib

    注意,需要 zlib, 需要 Tkinter pip install matplotlib import numpy as np import matplotlib.pyplot as plt plt ...

  7. CSS 教程 - 闭合浮动元素

    按照CSS规范,浮动元素(floats)会被移出文档流,不会影响到块状盒子的布局而只会影响内联盒子(通常是文本)的排列. 因此当其高度超出包含容器时,一般父容器不会自动伸长以闭合浮动元素. 但是有时我 ...

  8. drf作业01

    api\urls from django.conf.urls import url from . import views urlpatterns = [ url(r'^cars/$',views.C ...

  9. PHPStrom直接在编辑器打开php文件

    以下是自己配置PHP+Apache的开发环境,集成环境的话要换第二种方法(看个人配置):PHPStrom 如果希望直接在编辑器打开php文件,要做以下这几步配置. 第一种:非集成环境 1 2 3 第二 ...

  10. callee和caller属性的区别

    在函数内部,有两个特殊的对象:arguments和this .arguments是一个类数组对象,用于存放传入函数中的所有参数. callee是arguments对象的属性,caller是所有函数对象 ...