描述

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. LA3905 Meteor

    https://vjudge.net/problem/UVALive-3905 计算出每个点在相框中的时间段,扫描线做即可 关键在如何快速计算每个点在相框中的时间段.对每个点进行运动分解,进入的时间L ...

  2. 查看linux系统的文件inode号码使用情况

    :~$ df -i 文件系统 Inode 已用(I) 可用(I) 已用(I)% 挂载点 udev % /dev tmpfs % /run /dev/sda2 % / tmpfs % /dev/shm ...

  3. Java 函数优雅之道

    导读 随着软件项目代码的日积月累,系统维护成本变得越来越高,是所有软件团队面临的共同问题.持续地优化代码,提高代码的质量,是提升系统生命力的有效手段之一.软件系统思维有句话“Less coding, ...

  4. textarea限定字符输入及提示

    html <textarea type="text" name="goodsDesc" data-varify='goods' placeholder=& ...

  5. 读书笔记--iBATIS in Action 目录

    1.iBATIS的理念 2.iBATIS是什么 3.安装和配置iBATIS 4.使用以映射语句 5.执行非查询语句 6.使用高级查询技术 7.事务 8.使用动态SQL 9.使用高速缓存提高性能 10. ...

  6. Mysql千万级访问量架构

    1.HTML 静态化 其实大家都知道,效率最高.消耗最小的就是纯静态化的html页面,所以我们尽可能是我们的网站上的页面采用静态页面来实现,这个最简单的方法其实也是最有效的方法.但是对于大量内容并且频 ...

  7. cmd下带参数执行python文件

    在一个文件下下创建程序代码,     sys.argv 即后续cmd中需要传入的参数列表,     sys.argv[0]即要执行的文件名     sys.argv[n]即参数的字符串 # -*- c ...

  8. Python 字符编码处理总结

    Python中经常遇到这样那样的字符编码问题,尤其在处理网页源码时(特别是爬虫中): UnicodeDecodeError: 'XXX' codec can't decode bytes in pos ...

  9. JavaScript--取消a标签和form的submit提交默认行为

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  10. LintCode_69 二叉树前序遍历

    题目 给出一棵二叉树,返回其节点值的前序遍历. 和中序遍历基本相同 C++代码 vector<int> preorderTraversal(TreeNode *root) { // wri ...