POJ 1035
来源:互联网 发布:《不持有的生活》知乎 编辑:程序博客网 时间:2024/05/01 11:28
从给出的字典中查找是否有符合的单词。如果没有这再次检查多一个字母或者少一个字母或者替换一个字母的单词,并把这些单词
按输入顺序全部输出出来。
#include <cstdio>#include <cstring>#include <algorithm>#include <vector>#include <string>#include <set>using namespace std;const int maxn = 10000 + 10;const int SIZE = 26;vector<int> ss;char s[maxn][SIZE], t[SIZE];int length[maxn];int n = 0;set<string> vis;bool Right(char * t){ return vis.count(string(t));}bool Insert(char *p, char *t, int len){ int cnt = 0, pos = -1; for(int i = 0; i < len; ++i){ if(p[i] != t[i]) { pos = i; break; } } if(pos == -1) return true; for(int i = 0; i < pos; ++i){ if(p[i] != t[i]) return false; } for(int i = pos; i < len; ++i){ if(p[i + 1] != t[i]) return false; } return true;}bool Delete(char *p, char *t, int len){ return Insert(t, p, len - 1);}bool Replace(char *p, char *t, int len){ int cnt = 0; for(int i = 0; i < len; ++i){ if(p[i] != t[i]) cnt ++; if(cnt > 1) return false; } return true;}void Find(char *t, int len){ for(int i = 0; i < n; ++i){ if(length[i] == len && Replace(s[i], t, len)) ss.push_back(i); if(length[i] == len - 1 && Delete(s[i], t, len)) ss.push_back(i); if(length[i] == len + 1 && Insert(s[i], t, len)) ss.push_back(i); } sort(ss.begin(), ss.end());}int main(){ for(n = 0;;++n){ scanf("%s", s[n]); if(strcmp(s[n], "#") == 0) break; vis.insert(string(s[n])); length[n] = strlen(s[n]); } for(;;){ scanf("%s", t); if(strcmp(t, "#") == 0) break; ss.clear(); if(Right(t)){ printf("%s is correct\n", t); }else{ Find(t, strlen(t)); printf("%s:", t); for(int i = 0; i < ss.size(); ++i){ printf(" %s", s[ss[i]]); }printf("\n"); } } return 0;}
0 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
- Josephus问题
- Toast封装使用
- C/C++日期时间使用方法,struct tm, time_t, clock_t,计算循环所用时间
- 微信小程序之商城首页
- 51Nod - 1402 模拟 + 贪心
- POJ 1035
- Android开发--WIFI实现
- Udacity深度学习DeepLearning课程作业1—notMnist
- js实现跨设备自适应屏幕
- 使用qemu安装虚拟机
- python学习笔记——基础篇(0):python环境搭建
- myeclipse中如何启动tomcat7.0
- Selenium POM的批量实现方法和应用
- 【面向对象】——浅谈抽象类