链接:

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 ;
}

最新文章

  1. 谈谈pooling?
  2. java中的日期操作Calendar和Date
  3. HDU 5876 Sparse Graph BFS 最短路
  4. UVA 11076 - Add Again(组合)
  5. 词频junit测试
  6. 全网扫描扫描10000端口后的优化脚本&amp;域名列表指定端口的批量测试
  7. 设计模式之三:单例模式singleton
  8. Windows:文件服务器,访问进去不能查看到完整的文件
  9. html-制作导航菜单
  10. [转载]C#多线程学习(一) 多线程的相关概念
  11. MongoDB实战指南(三):MongoDB的锁机制
  12. haskell Types 和 Typeclasses
  13. Android Every day a new function:one
  14. 《JavaScript设计模式与开发实践》读书笔记之中介者模式
  15. 基于 Haproxy 构建负载均衡集群
  16. cal日历工具的用法
  17. 由Python通过__new__实现单例模式,所想到的__new__和__init__方法的区别
  18. 《前端之路》之 webpack 4.0+ 的应用构建
  19. 关于select的id以及value传给后台的问题
  20. 20172302 《Java软件结构与数据结构》实验三:查找与排序实验报告

热门文章

  1. 锐捷 rg-S2026f 学习笔记
  2. column count of mysql.proc is wrong. expected 20,found 16. the table is probably corruptd.
  3. inline修饰虚函数的问题
  4. 列表查询SQL语句改造
  5. 智能家居入门DIY——【三、GP2Y10之颗粒物传感器】
  6. app测试笔记记录
  7. 汇编_指令_FLAGS
  8. VMware vSphere Client下增加虚拟机磁盘空间的方法
  9. 43.国际化-app级别的资源文件
  10. 【Directshow】IFilterGraph::AddFilter方法参数问题&lt;转&gt;