博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
(字符串) Hidden String -- HDU -- 5311
阅读量:7199 次
发布时间:2019-06-29

本文共 2200 字,大约阅读时间需要 7 分钟。

链接:

 

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)

Total Submission(s): 1462    Accepted Submission(s): 521

Problem Description
Today is the 1st anniversary of BestCoder. Soda, the contest manager, gets a string 
s of length n. He wants to find three nonoverlapping substrings s[l1..r1]s[l2..r2]s[l3..r3] that:
1. 1l1r1<l2r2<l3r3n
2. The concatenation of s[l1..r1]s[l2..r2]s[l3..r3] is "anniversary".
 
Input
There are multiple test cases. The first line of input contains an integer 
T (1T100), indicating the number of test cases. For each test case:
There's a line containing a string s (1|s|100) consisting of lowercase English letters.
 

 

Output
For each test case, output "YES" (without the quotes) if Soda can find such thress substrings, otherwise output "NO" (without the quotes).
 

 

Sample Input
2 annivddfdersewwefary  nniversarya
 

 

Sample Output
YES NO

 

代码:

#include
#include
#include
#define N 150char s1[20] = "anniversary";char ch[N];char s[N][3][20];void Init(){ int j, z, w=0; for(j=1; j<=9; j++) for(z=1; z<=10-j; z++) { strncpy(s[w][0], s1, j); strncpy(s[w][1], s1+j, z); strcpy(s[w++][2], s1+j+z); }}int main(){ int t; scanf("%d", &t); Init(); while(t--) { char ch[N]; int i, a, b, len1, len2, flag=0; memset(ch, 0, sizeof(ch)); scanf("%s", ch); for(i=0; i<45; i++) { if(strstr(ch, s[i][0])) { a = strstr(ch, s[i][0])-ch; len1 = strlen(s[i][0]); a = a + len1; if(strstr(ch+a, s[i][1])) { b = strstr(ch+a, s[i][1])-(ch+a); ///就在这, 我在判断的时候还把字符串向后移了 a 位, 但在 ///计算的时候并没有用,这是最大的失误,难怪自己思路对了但一直提交错误 len2 = strlen(s[i][1]); b = a + b + len2; if(strstr(ch+b, s[i][2])) { flag = 1; break; } } } } if(flag) printf("YES\n"); else printf("NO\n"); } return 0;}

 

转载于:https://www.cnblogs.com/YY56/p/4749504.html

你可能感兴趣的文章
EOS之eosio.token合约的部署和发放token
查看>>
CDM中,创建一个或多个组合属性的唯一约束
查看>>
date详解
查看>>
试用期转正总结报告
查看>>
linux下的sed命令
查看>>
PHP全栈开发(一):CentOS 7 配置LAMP
查看>>
Struts的文件上传下载
查看>>
如何有效抓取SQL Server的BLOCKING信息
查看>>
华为编程大赛_将字符数组内的数字排序
查看>>
散列函数的应用及其安全性
查看>>
网球入门(一)网球打墙练习(转载)
查看>>
MyBatis(二)最简易的增、删、改、查
查看>>
jsapi4加载的首个图层的范围被默认作为地图范围,且不能修改的解决
查看>>
基于模式识别的的内窥镜肿瘤检测
查看>>
安装VMware tools (虚拟机:VMware 10.0.3 系统:centos 6.5)
查看>>
大家一起和snailren学java-(六)复用类
查看>>
Day20 Django的使用_基础
查看>>
Mac-OSX的Python3.5虚拟环境下安装Opencv
查看>>
windows ce 4.2/5.0/6.0/windows mobile设备直接连接PC端的SQLserver
查看>>
浏览器的工作流程
查看>>