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一律不去,求最多能够有多少个选手去 ...
随机推荐
- Annotation(一)——注解开发介绍
<p>在编程中,一直强调的一点就是注释的编写,注释的规范等等.尤其是越是核心,程序越复杂,逻辑越多的清空下,注释的编写对我们以后的阅读代码,维护软件起着至关重要的作用.一款软件有着好的注释 ...
- poj 1979 Red and Black(dfs水题)
Description There is a rectangular room, covered with square tiles. Each tile is colored either red ...
- (转)iOS7界面设计规范(7) - UI基础 - 交互性与反馈
现在只是周日下午,可怎样都觉得整个周末就这样即将过去了,不免沮丧.看了好多集小丸子了,又不免觉得现在其实是在放暑假,可以一天一天的窝在家里做任何事,任何事.再上一篇iOS7设计规范,然后本周末就到这里 ...
- Laravel 4 Blade模板引擎
http://my.oschina.net/5say/blog/201290 模板输出 基本输出 1 <!-- app/views/example.blade.php --> 2 < ...
- 一个不错的PPT,扁平化设计,开放资源,要的进来
开了那么多的博客,没做啥资源贡献,今天共享一个不错的PPT模板.例如以下图所看到的,须要的话留下邮箱 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbGFp ...
- [置顶] VB6基本数据库应用(三):连接数据库与SQL语句的Select语句初步
同系列的第三篇,上一篇在:http://blog.csdn.net/jiluoxingren/article/details/9455721 连接数据库与SQL语句的Select语句初步 ”前文再续, ...
- 解决 Google 重定向,体验 Google 本味
想要体验原汁原味的 Google(google.com),下面的方案是我用过的较方便的方案. 欢迎更正及补充 Chrome 扩展 Chrone 商店有一款禁止重定向的扩展 NoCountryRedir ...
- Asp.Net HttpApplication 事件汇总
Global.asax 文件,有时候叫做 ASP.NET 应用程序文件,提供了一种在一个中心位置响应应用程序级或模块级事件的方法.你可以使用这个文件实现应用程序安全性以及其它一些任务.下面让我们详细看 ...
- 【Solr初探】Solr安装,启动,查询,索引
1. 安装&启动 官网:http://lucene.apache.org/solr/ 下载源代码,解压,进入根目录(我把solr放在/usr/local/solr下) 在/usr/local/ ...
- 支付宝SDK快速入口链接
支付宝快捷支付SDK官方网站