您的位置:首页 > 其它

poj1035 Spell checker

2014-01-04 20:35 393 查看
这题目比较简单,把思路搞清楚就可以啦。

#include <stdio.h>
#include <string.h>
char words[10000+10][20];

int init(){
int cnt=0;
while(~scanf("%s",words[cnt])){
if(strcmp("#",words[cnt])==0) return cnt;
cnt++;
}
}
int judge(char a[],char b[]){
int success;
int la=strlen(a);
int lb=strlen(b);
int i,j,k;
int cnt=0;
if(la==lb){
for(i=0;i<la;++i)
if(a[i]!=b[i])
cnt++;
if(cnt==1) return 1;
}

if(la==lb+1)
for(i=0;i<la;++i){
success=1;
for(j=0,k=0;j<la&&k<lb;){
if(j==i){
j++;continue;
}
if(a[j]!=b[k]){
success=0;
}
j++;k++;
}
if(success==1) return 1;
}
if(la+1==lb)
for(i=0;i<lb;++i){
success=1;
for(j=0,k=0;j<la&&k<lb;){
if(k==i){
k++;continue;
}
if(a[j]!=b[k]){
success=0;
}
j++;k++;
}
if(success==1) return 1;
}
return 0;
}

void done(int cnt){
char tmp[20];
int i;
int success;
while(~scanf("%s",tmp)){
if(strcmp(tmp,"#")==0)
return;
success=0;
for(i=0;i<cnt;++i){
if(strcmp(words[i],tmp)==0){
printf("%s is correct\n",tmp);
success=1;
break;
}
}
if(success==1)
continue;
printf("%s:",tmp);
for(i=0;i<cnt;++i){
if( judge(words[i],tmp)==1){
printf(" %s",words[i]);
}
}
printf("\n");
}
return ;
}
int main(){
done(init());
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: