链接:

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. redis Linux 、Windows ubuntu 下的安装

    Redis 安装 2018-07-05 Window 下安装 下载地址:https://github.com/MSOpenTech/redis/releases. Redis 支持 32 位和 64 ...

  2. Python中表达式和语句及for、while循环练习

    Python中表达式和语句及for.while循环练习 1)表达式 常用的表达式操作符: x + y, x - y x * y, x / y, x // y, x % y 逻辑运算: x or y, ...

  3. Java进行spark计算

    首先在Linux环境安装spark: 可以从如下地址下载最新版本的spark: https://spark.apache.org/downloads.html 这个下载下来后是个tgz的压缩包,解压后 ...

  4. struts2学习(1)struts2 helloWorld

    一.struts2简介: 二.helloWorld: 1)工程结构: HelloWorldAction.java: package com.cy.action; import com.opensymp ...

  5. mac电脑 pip安装包后 撞到了系统python里面的解决方法

    /usr/local/Cellar/python@2/2.7.14_3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-pack ...

  6. 配置spring的log4j日志记录

    1.导入依赖包pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http: ...

  7. Hive 安装操作

    本篇为安装篇较简单: 前提:1: 安装了hadoop-1.0.4(1.0.3也可以)正常运行2:安装了hbase-0.94.3, 正常运行 接下来,安装Hive,基于已经安装好的hadoop,步骤如下 ...

  8. solr删除全部索引数据

    SOLR 删除全部索引数据: <delete><query>*:*</query></delete><commit/>

  9. NSString 与C++ string字符串的互转(转)

    . string 转换为 NSString std::string str("hello"); NSString *str=[NSString stringWithString:s ...

  10. iframe 元素会创建包含另外一个文档的内联框架(即行内框架)

    HTML 与 XHTML 之间的差异 在 HTML 4.1 Strict DTD 和 XHTML 1.0 Strict DTD 中,不支持 iframe 元素. 提示和注释: 提示:您可以把需要的文本 ...