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的更多相关文章
随机推荐
- VS2005连接MySQL C API
1.在属性添加:附加目录,附加依赖库,附加库目录: 2.在stdafx.h中加入: #include <winsock.h> #include "mysql.h" 3. ...
- tensorflow中张量的理解
自己通过网上查询的有关张量的解释,稍作整理. TensorFlow用张量这种数据结构来表示所有的数据.你可以把一个张量想象成一个n维的数组或列表.一个张量有一个静态类型和动态类型的维数.张量可以在图中 ...
- Javascript-循环输出菱形,并可菱形自定义大小
var Cen = 6;//定义菱形中部为第几行(起始值为0) //for循环输出菱形 document.write("<button onclick='xh()'>点我for循 ...
- 洛谷P3306 随机数生成器
题意:给你一个数列,a1 = x,ai = (A * ai-1 + B) % P,求第一个是t的是哪一项,或者永远不会有t. 解:循环节不会超过P.我们使用BSGS的思想,预处理从t开始跳√P步的,插 ...
- ubuntu中vi下删除键和上下左右键输入字符异常(ABCD)
刚安装的Ubuntu系统,使用vi编辑文本的时候, 出现以下现象: 点删除键输入了 D 回车无效 上下左右为字母 光标乱跳 原因: 自带的vi功能问题 解决: 卸载原有vi,重新安装完整版本vim 执 ...
- laravel 下载报错:Unable to guess the mime type as no guessers are available
在使用laravel的download()函数实现下载功能时,报错如下:Unable to guess the mime type as no guessers are available (Did ...
- 详谈Windows消息循环机制
一直对windows消息循环不太清楚,今天做个详细的总结,有说错的地方,请务必指出. 用VS2017新建一个win32 Application的默认代码如下: 程序入口 ...
- 使用openssl 生成网站证书
*.key是私钥文件 证书通常以.crt为后缀,表示证书文件 CSR(Certificate Signing Request)包含了公钥和名字信息.通常以.csr为后缀,是网站向CA发起认证请求的文件 ...
- 洛谷P1314 [NOIP2011提高组Day2T2] 聪明的质监员
P1314 聪明的质监员 题目描述 小T 是一名质量监督员,最近负责检验一批矿产的质量.这批矿产共有 n 个矿石,从 1到n 逐一编号,每个矿石都有自己的重量 wi 以及价值vi .检验矿产的流程是: ...
- 表格存储TableStore2.0重磅发布,提供更强大数据管理能力
表格存储TableStore是阿里云自研的面向海量结构化和半结构化数据存储的Serverless NoSQL多模型数据库,被广泛用于社交.物联网.人工智能.元数据和大数据等业务场景.表格存储Table ...