POJ 1035 Spell checker

来源:互联网 发布:ear cuff淘宝 编辑:程序博客网 时间:2024/06/15 17:54

题目链接:http://poj.org/problem?id=1035

题目描述:

      这题比较水,主要用来练下编程能力,就是给定一些单词,可以看成是将这些单词存在字典中,然后就输入一些字符串,对每一次字符串,如果能够找到,就输出**is correct,如果将该字符串增加一个字母,或者删除一个字母,或者修改一个字母得到的新字符串能够在字典中找到,就输出字典中的这个单词,如果都不能的话就输出回车。

#include<cstdio>#include<iostream>#include<cstring>#include<cmath>using namespace std ;char map[10005][29] ;bool cal(char t[], int n){int len1 = strlen(t), len2 = strlen(map[n]) ;//增if( len1-len2 == -1 ){int i, j ;bool judge = false ;for( i=j=0; i < len1 && j < len2 ; ){if( t[i] != map[n][j] ){if( judge )return false ;else{judge = true ;j++ ;//跳过}}else{i++ ;j++ ;}}return true ;}//减if( len1 - len2 == 1 ){int i, j ;bool judge = false ;for( i=j=0; i < len1 && j < len2; ){if( t[i] != map[n][j] ){if( judge )return false ;else{judge = true ;i++ ;//}}else{i++ ;j++ ;}}return true ;}//改if( len1 == len2 ){int i ;bool judge = false ;for( i = 0; i < len1; i++ ){if( t[i] != map[n][i] ){if( judge )return false ;elsejudge = true ;}}return true ;}return false ;}//int main(){//freopen("1234.in","r",stdin) ;int num = 0 ;while( scanf("%s",map[num]) != EOF && strcmp(map[num],"#") ){num++ ;}char m[20] ;scanf("%s",m) ;while( strcmp(m,"#") ){bool deal = false ;for( int i = 0; i < num; i++ ){if( strcmp(map[i],m) == 0 ){deal = true ;printf("%s is correct\n",m) ;break ;}}if( !deal ){printf("%s:",m) ;for( int i = 0; i < num; i++ ){if( cal(m,i) ){printf(" %s",map[i]) ;}}printf("\n") ;}scanf("%s",m) ;}return 0 ;}


0 0
原创粉丝点击