poj 1035
来源:互联网 发布:知乎html模板 编辑:程序博客网 时间:2024/05/01 11:58
这题是字符处理的一个典型题目,主要是在给出的“词典”中查找指定的单词,如果找到,就输出正确的,如果找不到完全一样的,就输出:
1,一个字母不同的
2,多一个字符的
3,少一个字符的
解题关键在不完全匹配的情况:比较时我们先算两个单词strlen之差,有三种情况
1,strlen(str)==strlen( ch[n] );有可能有一个字符不一样;逐个字符比较,统计不同字符数
2,strlen(str)+1==strlen( ch[n] );有可能少一个字符,逐个字符比较,如果有字符不同,则ch[n]字符下标往下移动一位,str不变,不同字符数加1
3,strlen(str)-1==strlen( ch[n] )有可能少一个字符,逐个字符比较,如果有字符不同,则str]字符下标往下移动一位,ch[n]不变,不同字符数加1
#include <stdio.h>#include <stdlib.h>#include <string.h>char ch[10010][16];char str[30];int isok(int n){int i,j,k;int l1=strlen(str),l2=strlen(ch[n]);switch(l1-l2){case 1:k=0;for(i=j=0;i<l1;)if(str[i]!=ch[n][j])k++,i++;elsei++,j++;if(k==1)return 1;break;case 0:k=0;for(i=j=0;i<l1;i++,j++)if(str[i]!=ch[n][j])k++;if(k==1)return 1;break;case -1:k=0;for(i=j=0;j<l2;)if(str[i]!=ch[n][j])k++,j++;elsei++,j++;if(k==1)return 1;break;}return 0;}int main(){int i=0,N=0;while(scanf("%s",ch[N]),strcmp(ch[N],"#")) N++;while(scanf("%s",str),strcmp(str,"#")){for(i=0;i<N;i++)if(strcmp(str,ch[i])==0){printf("%s is correct\n",str);break;}if(i==N){printf("%s:",str);for(i=0;i<N;i++)if(isok(i))printf(" %s",ch[i]);printf("\n");}}return 0;}
- POJ 1035
- Poj 1035
- POJ 1035
- poj 1035
- poj 1035
- poj 1035
- poj 1035
- POJ 1035
- poj.1035
- poj-1035
- poj 1035
- poj 1035
- poj 1035
- POJ 1035
- POJ 1035
- poj 1035
- poj-1035-Spell checker
- poj 1035 Spell checker
- 使用mysql命令检测select语句
- history.go(-1)和History.back()的区别
- 单播、多播和广播
- 关于background-image的一些使用心德和疑问!
- 数组个数匹配
- poj 1035
- C#线程系列讲座(1):BeginInvoke和EndInvoke方法
- POJ 4046
- 关于自动化测试,关于Agile,关于团队
- 快乐心情比一切都美丽
- uva 488
- VSFTPD 添加用户
- LCD驱动在OK2440开发板的移植
- runstats工具的配置及使用