hdu 5311 Hidden String(find,substr)
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: . ≤l1≤r1<l2≤r2<l3≤r3≤n . The concatenation of s[l1..r1], s[l2..r2], s[l3..r3] is "anniversary".
There are multiple test cases. The first line of input contains an integer T (≤T≤), 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.
For each test case, output "YES" (without the quotes) if Soda can find such thress substrings, otherwise output "NO" (without the quotes).
annivddfdersewwefary
nniversarya
YES
NO
题意:从s串中找出3段连续的字串组成“anniversary”
复习了下find,substr的用法,老是忘记
s.substr(i,j)表示从s串的i位置开始,长度为j的子串。
s.find(p,i),p为字串,表示从s串的i位置开始,寻找有没有等于p的子串,如果有返回s的首地址,否则返回-1
这题枚举“anniversary”的3个子串,在给出的s串中寻找就可以了!
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<cmath>
#include<stdlib.h>
#include<map>
using namespace std;
string s;
string goal="anniversary";
bool solve(){
for(int i=;i<=;i++){
int ans1=s.find(goal.substr(,i),);
if(ans1<) continue;
for(int j=;j+i<=;j++){
int ans2=s.find(goal.substr(i,j),ans1+i);
if(ans2<) continue;
int k=-i-j;
int ans3=s.find(goal.substr(i+j,k),ans2+j);
if(ans3<) continue;
return true;
}
}
return false;
}
int main()
{
int t;
scanf("%d",&t);
while(t--){
cin>>s;
if(solve()){
printf("YES\n");
}
else{
printf("NO\n");
}
}
return ;
}
hdu 5311 Hidden String(find,substr)的更多相关文章
- HDU 5311 Hidden String (暴力)
题意:今天是BestCoder一周年纪念日. 比赛管理员Soda有一个长度为n的字符串s. 他想要知道能否找到s的三个互不相交的子串s[l1..r1], s[l2..r2], s[l3..r3]满足下 ...
- hdu 5311 Hidden String
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5311 Hidden String Description Today is the 1st anniv ...
- hdu 5311 Hidden String (BestCoder 1st Anniversary ($))(深搜)
http://acm.hdu.edu.cn/showproblem.php?pid=5311 Hidden String Time Limit: 2000/1000 MS (Java/Others) ...
- HDU 5311 Hidden String (优美的暴力)
Hidden String Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) ...
- HDU 5414 CRB and String (字符串,模拟)
题意:给两个字符串s和t,如果能插入一些字符使得s=t,则输出yes,否则输出no.插入规则:在s中选定一个字符c,可以在其后面插入一个字符k,只要k!=c即可. 思路:特殊的情况就是s和t的最长相同 ...
- hdu 5311 Hidden String 字符串
BC一周年的题.这道题做比赛的时候A了小数据,终于评判的时候还是挂了,看来还是不认真思考的问题啊.交的时候 都没有信心过肯定是不行的.认真思考.敲一发,有信心过才是真正的acmer.赛后认真想了想,发 ...
- HDU 5707 Combine String (DP,LCS变形)
题意:给定三个字符串,问你第三个是不是由第一个和第二个组成的. 析:当时比赛是没有做出来啊...一直WA,就是没有判断长度,第一个和第二个和是不是和第三个一样,这个忘记... 我们用d[i][j]表示 ...
- hdu 1728:逃离迷宫(DFS,剪枝)
逃离迷宫 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- HDU 4173 Party Location(计算几何,枚举)
HDU 4173 题意:已知n(n<=200)位參赛选手的住所坐标.现要邀请尽可能多的选手来參加一个party,而每一个选手对于离住所超过2.5Km的party一律不去,求最多能够有多少个选手去 ...
随机推荐
- Android菜鸟的成长笔记(28)——Google官方对Andoird 2.x提供的ActionBar支持
在Google官方Android设计指南中(链接:http://www.apkbus.com/design/get-started/ui-overview.html)有一个新特性就是自我标识,也就是宣 ...
- POJ 1322 Chocolate
Chocolate Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8245 Accepted: 2186 Speci ...
- Android ActionBar应用实战,高仿微信主界面的设计
转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/26365683 经过前面两篇文章的学习,我想大家对ActionBar都已经有一个相对 ...
- Linux 常用系统命令-20160504
一.显示目录和文件的命令 1.ls(list) 功能说明: 列出目录内容. 语 法 : ls [-1aAbBcCdDfFgGhHiklLmnNopqQrRsStuUvxX][-I < 范 本 ...
- js数组 函数
js数组 filter(),map(),some(),every(),forEach(),lastIndexOf(),indexOf() 文章1:http://www.jb51.net/article ...
- MS-SQL数据库备份方法
一.手动备份 打开企业管理器 --> 右键点击需要备份的数据库 --> 所有任务 --> 备份数据库 或者: 查询分析器: use master backup database 数 ...
- Tomcat6+nginx集群,达到负载均衡和session复制
nginx+tomcat做web项目集群,达到负载均衡.故障转移.session复制功能. 1.nginx配置文件见上一篇“nginx配置文件(反向代理+集群+动静分离)” 2.tomcat集群,修改 ...
- ORACLE触发器的管理与实际应用【weber出品】
一.INSTEAD OF触发器 对于简单的视图可以执行INSERT,UPDATE和DELETE操作,但是对于复杂视图,不允许直接执行INSERT,UPDATE,DELETE操作,当视图出现以下任何一种 ...
- hprof教程
大部分内容参考http://www.linuxidc.com/Linux/2012-04/58178.htm J2SE中提供了一个简单的命令行工具来对java程序的cpu和heap进行 profili ...
- 一个支持实时预览的在线 Markdown 编辑器 - Markdoc
最近组内需要为一些项目和系统写文档,发表在公司内的文档平台上,这个平台并不支持markdown,所以打算做一个在线markdown编辑器,支持实时预览,并且可以很容易的迁移发表到公司文档平台上,所以就 ...