题目地址:http://poj.org/problem?id=1035
纯水题,但我感觉写的挺麻烦的。。根据历史经验,我以为我又要手残不断,调试半天。结果居然没调试就完美运行了。。然后提交1Y。。好爽。。。不调试直接AC的感觉真爽。。
代码如下:‘
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include <queue>
#include <map>
#include <algorithm>
using namespace std;
char s[11000][20];
int len[11000];
int main()
{
char st[20];
int i, j, len1, x, n, y, flag, k;
i=0;
while(scanf("%s",s[i])!=EOF)
{
if(s[i][0]=='#')
break;
len[i]=strlen(s[i]);
i++;
}
n=i;
while(scanf("%s",st)!=EOF)
{
if(st[0]=='#') break;
x=y=0;
len1=strlen(st);
for(i=0; i<n; i++)
{
if(strcmp(s[i],st)==0)
{
x=1;
break;
}
}
if(x)
printf("%s is correct\n",st);
else
{
printf("%s:");
for(i=0; i<n; i++)
{
y=0;
flag=0;
if(abs(len1-len[i])==0)
{
for(j=0; j<len1; j++)
{
if(s[i][j]!=st[j])
{
y++;
}
}
if(y<=1)
printf(" %s",s[i]);
}
else if(len1-len[i]==1)
{
k=0;
y=0;
for(j=0; j<len1; j++)
{
if(s[i][k]==st[j])
{
k++;
}
else
{
y++;
}
}
if(k==len[i]&&y<=1)
{
printf(" %s",s[i]);
}
}
else if(len[i]-len1==1)
{
k=0;
y=0;
for(j=0; j<len[i]; j++)
{
if(s[i][j]==st[k])
{
k++;
}
else
{
y++;
}
}
if(k==len1&&y<=1)
{
printf(" %s",s[i]);
}
}
}
printf("\n");
}
}
return 0;
}