链接:

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

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. 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 integer T (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

代码:

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

(字符串) Hidden String -- HDU -- 5311的更多相关文章

  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 (优美的暴力)

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

  4. HDU 5311:Hidden String

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

  5. 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 ...

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

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

  7. String HDU 5672(双指针)

    String HDU 5672(双指针) 传送门 题意:一个字符串中找到所有拥有不少于k个不同的字符的子串. import java.io.*; import java.util.*; public ...

  8. ASP.NET MVC 5 - 创建连接字符串(Connection String)并使用SQL Server LocalDB

    您创建的MovieDBContext类负责处理连接到数据库,并将Movie对象映射到数据库记录的任务中.你可能会问一个问题,如何指定它将连接到数据库? 实际上,确实没有指定要使用的数据库,Entity ...

  9. 窥探Swift之字符串(String)

    之前总结过Objective-C中的字符串<Objective-C精选字符串处理方法>,学习一门新语言怎么能少的了字符串呢.Swift中的String和Objective-C语言中NSSt ...

随机推荐

  1. NLTK在自然语言处理

    nltk-data.zip 本文主要是总结最近学习的论文.书籍相关知识,主要是Natural Language Pracessing(自然语言处理,简称NLP)和Python挖掘维基百科Infobox ...

  2. 常用的acl规则

    一.常用的acl规则        haproxy的ACL用于实现基于请求报文的首部.响应报文的内容或其它的环境状态信息来做出转发决策,这大大增强了其配置弹性.其配置法则通常分为两步,首先去定义ACL ...

  3. (5)函数式接口的简单使用之Predicate

    我们经常操作List,例如现在有一个功能要求在所有人中筛选出年龄在20岁以上的人. public class MyTest {     private final List<Person> ...

  4. HDU 2516 取石子游戏(斐波那契)

    取石子游戏 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  5. 浏览器禁用Cookie

    做JavaWeb的都知道Session的底层是使用Cookie来实现的,服务器端会在本地文件中保存session信息,并将sessionID发给客户端(浏览器),浏览器就会把这个sessionID(准 ...

  6. sql多表更新使用别名(小技巧)

    update     A set     A.CityRegionID=B.ParentID,     A.CityName=(select RegionName from Common_Region ...

  7. curl获取响应时间

    1.开启gzip请求curl -I http://www.sina.com.cn/ -H Accept-Encoding:gzip,defalte 2.监控网页的响应时间curl -o /dev/nu ...

  8. list.contains

    list.contains(o),系统会对list中的每个元素e调用o.equals(e),方法,加入list中有n个元素,那么会调用n次o.equals(e),只要有一次o.equals(e)返回了 ...

  9. MyBatis ehcache二级缓存

    ehcache二级缓存的开启步骤: 1.导入jar 2.在映射文件中指定用的哪个缓存 3.加一个配置文件,这个配置文件在ehcache jar包中就有 使增删改对二级缓存不刷新: 对一级缓存没有用的, ...

  10. Spring集成Mybatis配置文件的简单理解

    详情可见官方文档http://www.mybatis.org/spring/zh/index.html 一.需要配置的对象实例 1.SqlSessionFactoryBean 在 MyBatis-Sp ...