题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5311
题意:从给出的串 s 中找到3个子串然后把他们连在一起问是否能够成anniversary
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<math.h>
using namespace std;
#define INF 0xfffffff
#define N 1100
struct node
{
char s1[20],s2[20],s3[20];
int a, b, c;
}a[50];
char s[20] = {"anniversary"};
char s0[110];
bool judge(int i)
{
if(strstr(s0, a[i].s1)==NULL)
return false;
int pos;
pos=strstr(s0, a[i].s1)-s0;
if(strstr(s0+pos+a[i].a, a[i].s2)==NULL)
return false;
pos=strstr(s0+pos+a[i].a, a[i].s2)-s0;
if(strstr(s0+pos+a[i].b, a[i].s3)==NULL)
return false;
return true;
}
int main()
{
int k=0, x;
for(int i=1; i<=9;i++)
{
for(int j=1; j<=10-i; j++)
{
a[k].a=i;
a[k].b=j;
a[k].c=11-i-j;
x=0;
for(int ii=0;ii<i;ii++)
a[k].s1[x++]=s[ii];
a[k].s1[x]=‘\0‘;
x=0;
for(int ii=i;ii<i+j;ii++)
a[k].s2[x++]=s[ii];
a[k].s2[x]=‘\0‘;
x=0;
for(int ii=i+j;ii<11;ii++)
a[k].s3[x++]=s[ii];
a[k++].s3[x]=‘\0‘;
}
}
int T;
scanf("%d", &T);
while(T--)
{
scanf("%s",s0);
int flag=0;
for(int i=0; i<45; i++)
{
if(judge(i))
{
flag=1;
printf("YES\n");
break;
}
}
if(flag==0)
printf("NO\n");
}
return 0;
}
Hidden String---hdu5311(字符串处理)
原文:http://www.cnblogs.com/zhengguiping--9876/p/4961798.html