OpenJudge_1936:All in All
|
描述 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 样例输出 Yes |
解法:
#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的更多相关文章
随机推荐
- Luogu P2486 [SDOI2011]染色(树链剖分+线段树合并)
Luogu P2486 [SDOI2011]染色 题面 题目描述 输入输出格式 输入格式: 输出格式: 对于每个询问操作,输出一行答案. 输入输出样例 输入样例: 6 5 2 2 1 2 1 1 1 ...
- [原创]iFPGA-Cable FT2232H Xilinx / Altera / Lattice 三合一JTAG & UART调试器-详细使用说明
iFPGA-Cable调试器使用说明 全文分为6部分: 第0部分:实物.连线及其驱动安装说明 第1部分:Xilinx JTAG 第2部分:UART 第3部分:Altera JTAG 第4部分:Latt ...
- PHP1.6--数组
一.数组的键值操作函数 1.array_values() 函数作用是返回数组中所有元素的值,只有一个参数,规定传人给定数组,返回一个包含给定数组中所有值的数组,但不保留键名 被返回的数组将使用顺序的数 ...
- 【html、CSS、javascript-8】JavaScript作用域
JavaScript的作用域一直以来是前端开发中比较难以理解的知识点,对于JavaScript的作用域主要记住几句话 一.JavaScript中无块级作用域 在Java或C#中存在块级作用域,即:大括 ...
- idea小操作
1.IDEA 实用功能Auto Import:自动优化导包(自动删除.导入包) 2.设置System.out.println();等快捷键 3.将idea的背景修改为图片 4.Linux ifconf ...
- canvas用2d渲染出3d的感觉
好久没有写博客了,深究动画其实也就是setTimeout setInterval requestAnimationFrame很多人可能不熟悉requestAnimationFrame但是事实上和set ...
- 深入浅析python中的多进程、多线程、协程
深入浅析python中的多进程.多线程.协程 我们都知道计算机是由硬件和软件组成的.硬件中的CPU是计算机的核心,它承担计算机的所有任务. 操作系统是运行在硬件之上的软件,是计算机的管理者,它负责资源 ...
- id生成器
- NACOS集群搭建遇到的问题
搭建NACOS官网教程: https://nacos.io/zh-cn/docs/cluster-mode-quick-start.html 这里说的很详细了.也有中文的.我就记录一下在搭建集群的时候 ...
- Java方法传参的问题
1.基本数据类型(byte,short,int,long,float,double,boolean,char)的值传递,不改变其值 2.引用数据类型的值传递,改变其值 3.String类型虽然是引用数 ...