您的位置:首页 > 其它

poj 1035

2013-04-18 22:07 197 查看
暴力水过,79ms

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
char tx[10000+10][20];
char s[20];
int len[10000+10],loc[10000+10];
int main()
{
int i=0;
while(scanf("%s",tx[i]))
{
if(strcmp(tx[i],"#")==0) break;
len[i]=strlen(tx[i]);
i++;
}
int tot=0,k,p,flag;
while(scanf("%s",s))
{
tot=0;
if(strcmp(s,"#")==0) break;
int j,le=strlen(s);
for(j=0;j<i;j++)
{
flag=0;
if(le==len[j])
{
for(k=0;k<le&&flag<=1;k++)
{
if(s[k]!=tx[j][k]) flag++;
}
if(flag==0) break;
else if(flag==1) loc[tot++]=j;
}
else if(le==(len[j]+1))
{
flag=0;
for(k=0,p=0;k<len[j]&&flag<=1;)
{
if(s[p]!=tx[j][k])
{
flag++;
p++;
}
else
{
p++;
k++;
}
}
if(flag<=1) loc[tot++]=j;
}
else if((le+1)==len[j])
{
flag=0;
for(k=0,p=0;p<le&&flag<=1;)
{
if(s[p]!=tx[j][k])
{
flag++;
k++;
}
else
{
p++;
k++;
}
}
if(flag<=1) loc[tot++]=j;
}
}
if(j<i) printf("%s is correct\n",s);
else
{
printf("%s:",s);
for(k=0;k<tot;k++) printf(" %s",tx[loc[k]]);
printf("\n");
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: