poj1035
来源:互联网 发布:林珊珊的淘宝店 编辑:程序博客网 时间:2024/04/30 09:03
题目意思很简单,给定几个字符串,若在词典中有相匹配,输出correct
如果与词典中的词差距一个字符,可以通过添加,删除,修改变为正确,那么输出
没有就不输出
解法:水题,暴力就可以,注意易错部分的匹配
代码可能比较难理解
#include<stdio.h>#include<string.h>char s[10010][20];int n,m,len[10010];bool right(char c[30]){for(int i=0;i<n;++i) if(!strcmp(c,s[i])) return 1;return 0;}inline int abs(int a){ return (a^(a>>31))-(a>>31);} bool ok(char* a,char* b){int l1=strlen(a);int l2=strlen(b);if(l1>l2){ l1+=l2;l2=l1-l2;l1-=l2;char* c=a;a=b;b=c;}if(l1==l2) {bool cnt=0;for(int i=0;i<l1;++i)if(cnt&&a[i]!=b[i])return 0;else cnt|=(a[i]!=b[i]);return 1;}else {bool cnt=0;for(int i=0;i<l2;++i)if(cnt&&a[i-cnt]!=b[i])return 0;else cnt|=(a[i-cnt]!=b[i]);return 1;}}int main(){scan:scanf("%s",s[n]);len[n]=strlen(s[n]);if(*s[n++]=='#') n--;else goto scan;char c[30]; int l;work:scanf("%s",c);if(*c=='#') goto end;if(right(c)) {printf("%s is correct\n",c);goto work;}l=strlen(c);printf("%s:",c);for(int i=0;i<n;++i)if(abs(len[i]-l)<2) if(ok(s[i],c)) printf(" %s",s[i]);puts("");goto work;end: return 0;}
1 0
- poj1035
- poj1035
- poj1035
- poj1035
- poj1035
- poj1035
- poj1035
- POJ1035
- poj1035
- poj1035
- poj1035
- POJ1035
- poj1035
- 查找 poj1035
- poj1035 模拟
- POJ1035(字符串)
- POJ1035解题报告
- poj1035 Spell checker
- windows下 Mysql 错误1067 Can't open and lock privilege tables: Table 'mysql.user' doesn't exist
- Spiral Matrix 螺旋矩阵
- 我的数组类
- Java冒泡排序
- pat_BL_1003
- poj1035
- Tribon展望之工程数据在云端
- new/delete 和malloc/free 的区别
- 网络协议
- BZOJ 4551 树
- 四个绘图DC的使用总结
- leetcode 118. Pascal's Triangle
- Eclipse在高分屏下图标过小的解决方法
- Android打造不一样的新手引导页面(一)