题意:给一个指定的字符串a,要求分成三段,然后再给定另外一个字符串b,要求a中的三段能否在b中找到。

思路:枚举+模拟,首先枚举给定的字符串a,因为分成三段,所以一共有(1+9)*9/2种情况,对于分成后的三段p,q,r先查找p在b中匹配后的下标,然后减去b,结果是匹配字符的前一个下标,所以这个时候要加上匹配的长度,才能确定下个匹配从哪里开始,最后只要匹配成功即可退出。

#include<cstring>
#include<stdio.h>
#include<iostream>
using namespace std;
#define MAX 110
int t,flag;
char a[] = "anniversary", b[MAX];
bool solve(char s[])
{
for(int i = 0; i <= 8; i++)
{
for(int j = i + 1; j <= 9; j++)
{
strcpy(b, a);
b[i + 1] = 0;
flag = strstr(s, b) - s;
if(flag < 0) continue;
flag += i + 1;
strcpy(b, a + i + 1);
b[j - i] = 0;
flag = strstr(s + flag, b) - s;
if(flag < 0) continue;
flag += j - i;
strcpy(b, a + j + 1);
b[10- j] = 0;
flag = strstr(s + flag, b) - s;
if(flag < 0) continue;
return true;
}
}
return false;
}
int main()
{
cin>>t;
while(t--)
{
char s[MAX];
scanf("%s", s);
if(solve(s))
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return 0;
}

HDU5311的更多相关文章

  1. HDU5311 Hidden String

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

  2. Hidden String(深搜)

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

  3. C/C++用strncpy()与strstr()分割与匹配查找字符串

    最近做题遇到分割与匹配字符串的题目(hdu5311),看来别人的代码,才知道有strncpy()和strstr()函数,于是搜集了一点资料,记录一下基本用法. 一.strncpy() char * s ...

随机推荐

  1. 分布式系统间通信之RPC的基本概念(六)

    RPC(Remote Procedure Call Protocol)远程过程调用协议.一个通俗的描述是:客户端在不知道调用细节的情况下,调用存在于远程计算机上的某个对象,就像调用本地应用程序中的对象 ...

  2. Qt之模型/视图(自定义按钮)(使用QStyleOption的子类进行drawControl,和我用的方法完全不一样)

    http://blog.csdn.net/liang19890820/article/details/50974059

  3. C++ STL的各种实现版本

    ANSI/ISO的C++ STL规范版本正式通过以后,各个C++编译器厂商就可以依照标准所描述的原型去实现C++ STL泛型库,于是出现多种符合标准接口,但具体实现代码不同的泛型库,主要有: HP S ...

  4. 【JavaScript】

    右键禁用.防止文字选中 .返回选中的文本 JavaScript 原理 Javascript高性能动画与页面渲染 前端不为人知的一面--前端冷知识集锦 屏幕外去计算值,position:absolute ...

  5. javascript 路线整理

    前端开发很重要,编写脚本也不容易. 总结我以前的前端学习经历,基本是一团乱麻:css+javascript是在大三自学的,当时自己做课程设计,逼着自己在一个月之内,写了一个半成品的j2ee网站.当时, ...

  6. 源码安装Ansible

    一.Ansible介绍 ansible是一款的自动化运维工具,基于Python开发,集合了众多运维工具(puppet.cfengine.chef.func.fabric)的优点,实现了批量系统配置.批 ...

  7. CMOS Sensor的调试经验分享

    转自:http://bbs.52rd.com/forum.php?mod=viewthread&tid=276351 CMOS Sensor的调试经验分享 我这里要介绍的就是CMOS摄像头的一 ...

  8. android网络图片的下载

    android网络图片的下载 /** * Get image from newwork * * @param path * The path of image * @return byte[] * @ ...

  9. Nodejs in Visual Studio Code 07.学习Oracle

    1.开始 Node.js:https://nodejs.org OracleDB: https://github.com/oracle/node-oracledb/blob/master/INSTAL ...

  10. [Locked] Smallest Rectangle Enclosing Black Pixels

    An image is represented by a binary matrix with 0 as a white pixel and 1 as a black pixel. The black ...