B. Hidden String

Time Limit: 1 Sec

Memory Limit: 256 MB

题目连接

http://bestcoder.hdu.edu.cn/contests/contest_chineseproblem.php?cid=610&pid=1002

Description

今天是BestCoder一周年纪念日. 比赛管理员Soda有一个长度为n的字符串s. 他想要知道能否找到s的三个互不相交的子串s[l1..r1], s[l2..r2], s[l3..r3]满足下列条件:

  1. 1≤l1≤r1<l2≤r2<l3≤r3≤n

  2. s[l1..r1], s[l2..r2], s[l3..r3]依次连接之后得到字符串"anniversary".

Input

输入有多组数据. 第一行有一个整数T (1≤T≤100), 表示测试数据组数. 然后对于每组数据:

一行包含一个仅含小写字母的字符串s (1≤|s|≤100).

Output

对于每组数据, 如果Soda可以找到这样三个子串, 输出"YES", 否则输出"NO".

Sample Input

2
annivddfdersewwefary
nniversarya

Sample Output

YES
NO

HINT

题意

题解:

DFS

代码

 #include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef __int64 ll;
using namespace std; typedef __int64 ll;
const int inf = (int)1E9+;
inline ll read()
{
ll x=,f=;
char ch=getchar();
while(ch<''||ch>'')
{
if(ch=='-')f=-;
ch=getchar();
}
while(ch>=''&&ch<='')
{
x=x*+ch-'';
ch=getchar();
}
return x*f;
} //******************************* int T;
char s[];
char s1[] = "anniversary";
bool dfs(int num,int k,int i)
{
if(num >= ) return ;
while(s[k] != '\0')
{
if(s[k] == s1[i])
{
k++;
i++;
if(dfs(num+,k,i)) return true;
if(s1[i] == '\0')return true;
}
else
{
break;
}
}
for(; s[k] != '\0'; ++k)
{
if(s[k] == s1[i])
{
if(dfs(num+,k,i)) return true;
}
}
return false;
}
int main()
{
cin>>T;
while(T--)
{
scanf("%s",s);
int flag=;
for(int i=; s[i]!='\0'; ++i)
{
if(s[i]=='a')
{
flag=dfs(,i,);
if(flag) break;
}
}
if(flag) printf("YES\n");
else printf("NO\n");
}
return ;
}

最新文章

  1. 如何使用DOS命令(cd命令)
  2. 【BZOJ1034】[ZJOI2008]泡泡堂BNB 贪心
  3. Linux 进程通信(无名管道)
  4. Week,Month, Year 日期区间辅助类
  5. Java hashCode
  6. mongodb的查询方式与sql语句对比
  7. Swift学习笔记十四
  8. MyBatis动态SQL语法
  9. 20160427Struts2--入门1
  10. JavaScript学习笔记--ES6学习(四) 字符串的扩展
  11. Android学习----Activity
  12. Android的BUG(四) - Android app的卡死问题
  13. HTML学习笔记——各种居中对齐
  14. Redis从入门到精通
  15. js封装成插件-------Canvas统计图插件编写
  16. 201521123022 《Java程序设计》 第十一周学习总结
  17. Unity使用脚本进行批量动态加载贴图
  18. 【转载】“宇宙最强” IDE,Visual Studio 2019 正式发布
  19. System.Collections里的一些接口
  20. JS 引用类型之Object

热门文章

  1. 闲来无事,用Java的软引用写了一个山寨的缓存
  2. 转:Java NIO系列教程(四) Scatter/Gather
  3. 用JSON-server模拟REST API(一) 安装运行
  4. Spring常用annotation标签
  5. matlab 之cov 协方差
  6. Entity Framework Repository模式
  7. iphone/ipad图标尺寸
  8. [BZOJ1171][BZOJ2892]大sz的游戏
  9. Android判断网络是否连接
  10. HDOJ 2546饭卡(01背包问题)