HDU5311
题意:给一个指定的字符串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的更多相关文章
- HDU5311 Hidden String
Problem Description Today is the 1st anniversary of BestCoder. Soda, the contest manager, gets a str ...
- Hidden String(深搜)
Hidden String Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) ...
- C/C++用strncpy()与strstr()分割与匹配查找字符串
最近做题遇到分割与匹配字符串的题目(hdu5311),看来别人的代码,才知道有strncpy()和strstr()函数,于是搜集了一点资料,记录一下基本用法. 一.strncpy() char * s ...
随机推荐
- optimize performance
http://www.cnblogs.com/fullhouse/archive/2012/01/05/2313105.html http://www.cnblogs.com/fullhouse/ar ...
- Pots
poj3414:http://poj.org/problem?id=3414 题意:给你两个罐子的体积,然后让你只用这两个罐子量出给定k体积的水.题解:这里可以把两个罐子看成是一个二维的图,然后体积的 ...
- Election Time
Election Time Time Limit: 1000MS Memory limit: 65536K 题目描述 The cows are having their first election ...
- delphi XML 原来可以玩接口
以下代码旨在 脱离TXMLDocument 操作 xml unit Unit3; interface uses Windows, Messages, SysUtils, Variants, Class ...
- 关于Mysql当中"Got error 134 from storage engine"的解决办法
今天在开发程序的时候,有一个表, 当调用这个类别时总是调用不出来,很是恼火.后台打印sql语句为: SELECT * FROM `xx_article` WHERE `cid1` =6 LIMIT 0 ...
- bzoj1221
网络流与线性规划24题中的餐巾计划吧明显要拆点吧,把每一天拆成2个点,i,i+n起点 终点 容量 费用 s i inf c 每天都可以购买新毛巾 i ...
- 【模拟】NCPC 2014 D Dice Game
题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1790 题目大意: 两个人,每个人有两个骰子,每个骰子可以等概率取[a,b],问哪个人两 ...
- Unique Paths II ——LeetCode
Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...
- ink_test
- CodeForces 689A -Mike and Cellphone
题目链接:http://acm.hust.edu.cn/vjudge/problem/visitOriginUrl.action?id=412142 题目大意: 给定一个0-9数字键盘,随后输入一个操 ...