Hidden String

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

Total Submission(s): 52    Accepted Submission(s): 25

Problem Description
Today is the 1st anniversary of BestCoder. Soda, the contest manager, gets a strings
of length n.
He wants to find three nonoverlapping substrings s[l1..r1],s[l2..r2],s[l3..r3]
that:



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



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 integerT(1≤T≤100),
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
 

Source

 

题目链接:

pid=5311">http://acm.hdu.edu.cn/showproblem.php?

pid=5311



题目大意:问在一个字符串里能不能找到连续三个区间拼成anniversary



题目分析:暴力,枚举每段的长度

#include <cstdio>
#include <cstring>
char s[200], con[] = "anniversary"; int main()
{
int T;
scanf("%d", &T);
while(T--)
{
scanf("%s", s);
int len = strlen(s);
bool flag = false;
for(int i = 0; i <= 8; i++)
{
for(int j = i + 1; j <= 9; j++)
{
int k = 0;
while(k < len && strncmp(con, s + k, i + 1) != 0)
k ++;
if(k == len)
break;
k += i + 1;
while(k < len && strncmp(con + i + 1, s + k, j - i) != 0)
k ++;
if(k == len)
break;
k += j - i;
while(k < len && strncmp(con + j + 1, s + k, 10 - j) != 0)
k ++;
if(k != len)
{
flag = true;
break;
}
}
}
if(flag)
puts("YES");
else
puts("NO");
}
}

HDU 5311 Hidden String (优美的暴力)的更多相关文章

  1. hdu 5311 Hidden String

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5311 Hidden String Description Today is the 1st anniv ...

  2. 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)  ...

  3. HDU 5311 Hidden String (暴力)

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

  4. hdu 5311 Hidden String 字符串

    BC一周年的题.这道题做比赛的时候A了小数据,终于评判的时候还是挂了,看来还是不认真思考的问题啊.交的时候 都没有信心过肯定是不行的.认真思考.敲一发,有信心过才是真正的acmer.赛后认真想了想,发 ...

  5. hdu 5311 Hidden String(find,substr)

    Problem Description Today is the 1st anniversary of BestCoder. Soda, the contest manager, gets a str ...

  6. hdoj 5311 Hidden String(KMP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5311 思路分析:该问题要求在字符串中是否存在三个不相交的子串s[l1..r1], s[l2..r2], ...

  7. HDU 5311:Hidden String

    Hidden String  Accepts: 437  Submissions: 2174  Time Limit: 2000/1000 MS (Java/Others)  Memory Limit ...

  8. BestCoder 1st Anniversary ($) 1002.Hidden String

    Hidden String Accepts: 437 Submissions: 2174 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 26 ...

  9. BestCoder 1st Anniversary B.Hidden String DFS

    B. Hidden String Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://bestcoder.hdu.edu.cn/contests/co ...

随机推荐

  1. angular6 NG-ZORRO 的使用

    1:关于 NG-ZORRO中使用它自己组件改变样式时得使用样式穿透 “class” :: ng-deep "class"

  2. 深度优先搜索DFS和广度优先搜索BFS简单解析

    转自:https://www.cnblogs.com/FZfangzheng/p/8529132.html 深度优先搜索DFS和广度优先搜索BFS简单解析 与树的遍历类似,图的遍历要求从某一点出发,每 ...

  3. Raspberry Pi开发之旅-控制蜂鸣器演奏乐曲

    一.无源蜂鸣器和有源蜂鸣器 步进电机以及无源蜂鸣器这些都需要脉冲信号才能够驱动,这次尝试用GPIO的PWM接口驱动无源蜂鸣器弹奏一曲<一闪一闪亮晶晶>. 无源蜂鸣器: 无源内部没有震荡源, ...

  4. Ionic2/angularJs2中的静态类 PhotoLibrary 调用不上

    photoLibrary调用报错:No provider for PhotoLibrary: 在调用相册文件时有用到photolibrary,总有些莫名的报错,3月份的时候这个坑让我不知所措,现在写下 ...

  5. luogu P4137 Rmq Problem / mex 主席树 + 思维

    Code: #include<bits/stdc++.h> #define maxn 200001 using namespace std; void setIO(string s) { ...

  6. Ajax 调用案例及错误捕捉

    function postFunc() { var scoreResultStr = readyData(); $.ajax({ type: "post", url: " ...

  7. Script:shell脚本生成随机字符串

    #!/bin/bash # bash generate random alphanumeric string # # bash generate random character alphanumer ...

  8. c++运行程序闪退

        以最简单程序为例       法一:在主函数末尾下一行getchar();即可.需要注意的是这种方法并不适合所有程序,       法二:<1>先在程序开头加上头文件#includ ...

  9. <SpringMvc>入门二 常用注解

    1.@RequestMapping @Target({ElementType.METHOD, ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME ...

  10. 动态 SQL(2)

    前面我们学习了使用动态 SQL 的 if.where.trim元素来处理一些简单查询操作,但对于一些 SQL 语句中含有 in 条件,需要迭代条件集合来生成的情况,我们就需要使用 foreach 标签 ...