两个for循环 2.632s水过。。。。。。。。。
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#define MAXN 25000+5
using namespace std;
typedef struct node
{
char str[20];
int len;
} node ;
node word[MAXN];
bool suit(int x,int y)
{
if(word[x].len==word[y].len)
{
int flag=0;
for(int i=0,j=0; word[x].str[i]!='\0'; i++,j++)
{
if(word[x].str[i]!=word[y].str[j])
{
if(flag) return false;
else flag=1;
}
}
}
else if(word[x].len+1==word[y].len)
{
int flag=0;
for(int i=0,j=0; word[y].str[i]!='\0'; i++)
{
if(word[y].str[i]!=word[x].str[j])
{
if(flag) return false;
else flag=1;
continue;
}
j++;
}
}
else if(word[x].len-1==word[y].len)
{
int flag=0;
for(int i=0,j=0; word[x].str[i]!='\0'; i++)
{
if(word[x].str[i]!=word[y].str[j])
{
if(flag) return false;
else flag=1;
continue;
}
j++;
}
}
else return false;
return true;
}
int main()
{
// freopen("in.txt","r",stdin);
int d[MAXN],cnt=0;;
while(scanf("%s",word[cnt].str)!=EOF)
{
word[cnt].len=strlen(word[cnt].str);
cnt++;
}
int maxx=0;
for(int i=0; i<cnt; i++)
{
d[i]=1;
for(int j=0; j<i; j++)
{
if(suit(i,j))
{
d[i]=max(d[i],d[j]+1);
maxx=max(maxx,d[i]);
}
}
}
printf("%d\n",maxx);
}