POJ 1035 Spell checker(字符串比较)
来源:互联网 发布:sql注入语句 编辑:程序博客网 时间:2024/04/28 20:09
题意
输入一部字典,输入若干单词
1、 若某个单词能在字典中找到,则输出corret
2、 若某个单词能通过 变换 或 删除 或 添加一个字符后,在字典中找得到,则输出这些单词,输出顺序根据 输入的那部字典的字典序
3、 若某个单词无论操作与否都无法在字典中找得到,则输出空
POJ 1035
分析
存下字典单词,对每个要查找的单词,暴力扫描字典单词,根据单词长度,选择操作并检查。
#include<iostream>#include<cstring>#include<cstdio>using namespace std;char dic[10002][17],temp[20];int ans[10002];int sum,len_t;void fun(){ int len_dic,cnt=0; for(int i=0;i<sum;i++){ int dif=0,k,p; len_dic=strlen(dic[i]); if(len_dic==len_t){ for(k=0;k<len_dic;k++){ if(temp[k]!=dic[i][k]) dif++; if(dif>=2) break; } if(dif==0) { cout<<temp<<" is correct"<<endl; return ; } else if(dif==1) ans[cnt++]=i; } else if(len_dic==len_t-1){ for(k=0,p=0;k<len_t;k++,p++){ if(temp[k]!=dic[i][p]){ dif++;p--; } if(dif>=2) break; } if(dif==1) ans[cnt++]=i; } else if(len_dic==len_t+1){ for(k=0,p=0;p<len_dic;k++,p++){ if(temp[k]!=dic[i][p]){ dif++;k--; } if(dif>=2) break; } if(dif==1) ans[cnt++]=i; } } cout<<temp<<":"; for(int i=0;i<cnt;i++) cout<<" "<<dic[ans[i]]; cout<<endl;}int main(){ //freopen("in.txt","r",stdin); sum=0; while(gets(dic[sum])&&dic[sum][0]!='#') sum++; while(gets(temp)&&temp[0]!='#'){ len_t=strlen(temp); fun(); }}
0 0
- POJ 1035 Spell checker(字符串比较)
- 字符串 模拟 Spell checker (poj 1035)
- poj 1035 Spell checker(字符串处理)
- POJ 1035 Spell checker(字符串处理)
- POJ 1035 Spell checker 字符串
- POJ 1035-Spell checker(字符串)
- POJ 1035 Spell checker (字符串)
- Spell checker (poj 1035 字符串)
- poj 1035 Spell checker &nyoj 162 Spell checker(优化)
- poj 1035 Spell checker ( 字符串处理 )
- POJ 1035 Spell checker (字符串模拟)
- POJ Spell checker(1035)-字符串处理
- POJ 1035:Spell checker:字符串操作
- poj 1035 Spell checker 字符串,暴力
- POJ 1035 Spell checker【字符串暴力处理】
- POJ 1035 Spell checker 字符串暴力
- POJ 1035 Spell checker 字符串容错检查
- POJ 1035 Spell checker 【字符串暴力查找】
- 算法八皇后问题
- VirtualBox双机调试
- iOS开发中WebView的使用
- [POJ 2516]Minimum Cost[费用流][建图]
- jquery ajax级联二级下拉,jquey select级联
- POJ 1035 Spell checker(字符串比较)
- 「C++ Primer」3.22 迭代器未定义操作导致段错误问题
- mysql5.6配置版
- TCP的三次握手(建立连接)和四次挥手(关闭连接)
- Eclipse各种快捷键方式
- JVM
- Linux---centos编译安装ffmpeg
- php发送邮件类
- VMware Workstation 12 Player安装Windows10 x64出现的问题