POJ 1035.Spell checker
来源:互联网 发布:淘宝lee 编辑:程序博客网 时间:2024/05/13 04:36
题目:http://poj.org/problem?id=1035
AC代码(C++):
#include <iostream>#include <algorithm>#include <stdio.h>#include <vector>#include <queue>#include <math.h>#include <string>using namespace std;int main(){vector<string> dic;for(;;){string word;cin>>word;if(word.at(0)=='#')break;dic.push_back(word);}for(;;){string word;cin>>word;if(word.at(0)=='#')break;vector<string> rs;bool flag = false;for(vector<string>::iterator it = dic.begin(); it != dic.end(); it++){if(word.length()==it->length()){int cnt = 0;for(int i = 0; i < word.length(); i++){if(it->at(i)!=word.at(i))cnt++;}if(cnt==0){cout<<word<<" is correct\n";flag = true;}else if(cnt==1){rs.push_back(*it);}}else if(word.length()-it->length()==1){for(int i = 0; i < it->length(); i++){if(it->at(i)!=word.at(i)){string tmp = word;tmp.erase(i,1);if(tmp.compare(*it)==0){rs.push_back(*it);break;}break;}if(i+1==it->length()){rs.push_back(*it);break;}}}else if(it->length()-word.length()==1){for(int i = 0; i < word.length(); i++){if(it->at(i)!=word.at(i)){string tmp = *it;tmp.erase(i,1);if(tmp.compare(word)==0){rs.push_back(*it);break;}break;}if(i+1==word.length()){rs.push_back(*it);break;}}}}if(!flag){cout<<word<<": ";for(vector<string>::iterator it = rs.begin(); it != rs.end(); it++){cout<<*it;if(it+1!=rs.end())cout<<' ';}cout<<endl;}}}总结:水题, 分3种情况, 其实是2种, 字符多一个和少一个其实是一样的, 换一下判断就行.
阅读全文
0 0
- POJ 1035.Spell checker
- poj-1035-Spell checker
- poj 1035 Spell checker
- 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
- poj 1035 Spell checker
- poj 1035 Spell checker
- poj 1035 Spell checker
- POJ 1035 Spell checker
- POJ 1035 Spell checker
- poj 1035 Spell checker
- POJ 1035 Spell checker
- poj 1035 Spell checker
- Ubuntu 17.10 “Artful Aardvark” 发布首个 Beta
- Java常见缺陷模式
- 校门外的树
- 数学中的常见符号
- Python魔术方法详解
- POJ 1035.Spell checker
- Python--Virtualenv简明教程
- epoll触发事件的分析
- 阿里云CentOS 7 搭建图片服务器 (Nginx+Vsftpd)
- 史上最简单的SpringCloud教程 | 第九篇: 服务链路追踪(Spring Cloud Sleuth)
- android studio 添加aar文件引用
- 浅析 Hinton 最近提出的 Capsule 计划
- RESTful风格WebService简介
- Oracel还原数据-管理