PKU 1035 Spell checker(Vector+String应用)
题目大意:原题链接
1输入一个字符串,如果字典中存在该字符串,直接输出,否则;
2.删除,替换,或插入一个字母。如果使得输入字符串==字典中已经有的单词,输出该单词,否则。
3.直接输入下一个字符串,继续匹配.
#include<vector>
#include<string>
#include<iostream>
using namespace std;
string s;
int main(){
vector<string> dict;
while(cin>>s){
if(s=="#") break;
dict.push_back(s);
}
while(cin>>s){
if(s=="#") break;
cout<<s;
int len1=s.size();
bool sign=false;
for(int i=;i<dict.size();i++){
if(s==dict[i]){
cout<<" is correct"<<endl;
sign=true;break;
}
}
if(!sign){
cout<<":";
//枚举字典中每一个单词进行查找
for(int i=;i<dict.size();i++){
int len2=dict[i].size();
int d=,delta=len2-len1;
if(delta>||delta<-) continue;
if(delta==-){//删除
for(int j=;j<len1;j++){
if(s[j]==dict[i][d])
d++;
}
if(d==len2) cout<<' '<<dict[i];
}
else if(delta==){//替换
for(int j=;j<len1;j++){
if(s[j]!=dict[i][j])
d++;
}
if(d==) cout<<' '<<dict[i];
}
else if(delta==){//插入
for(int j=;j<len2;j++){
if(s[d]==dict[i][j])
d++;
}
if(d==len1) cout<<' '<<dict[i];
}
}
cout<<endl;
}
}
}
PKU 1035 Spell checker(Vector+String应用)的更多相关文章
- poj 1035 Spell checker
Spell checker Time Limit: 2000 MS Memory Limit: 65536 KB 64-bit integer IO format: %I64d , %I64u J ...
- poj 1035 Spell checker ( 字符串处理 )
Spell checker Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 16675 Accepted: 6087 De ...
- [ACM] POJ 1035 Spell checker (单词查找,删除替换添加不论什么一个字母)
Spell checker Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 18693 Accepted: 6844 De ...
- POJ 1035 Spell checker 字符串 难度:0
题目 http://poj.org/problem?id=1035 题意 字典匹配,单词表共有1e4个单词,单词长度小于15,需要对最多50个单词进行匹配.在匹配时,如果直接匹配可以找到待匹配串,则直 ...
- POJ 1035 Spell checker(串)
题目网址:http://poj.org/problem?id=1035 思路: 看到题目第一反应是用LCS ——最长公共子序列 来求解.因为给的字典比较多,最多有1w个,而LCS的算法时间复杂度是O( ...
- poj 1035 Spell checker(水题)
题目:http://poj.org/problem?id=1035 还是暴搜 #include <iostream> #include<cstdio> #include< ...
- 【POJ】1035 Spell checker
字典树. #include <iostream> #include <cstdio> #include <cstring> #include <cstdlib ...
- POJ 1035 Spell checker (模拟)
题目链接 Description You, as a member of a development team for a new spell checking program, are to wri ...
- POJ 1035 Spell checker 简单字符串匹配
在输入的单词中删除或替换或插入一个字符,看是否在字典中.直接暴力,172ms.. #include <stdio.h> #include <string.h> ]; ][], ...
随机推荐
- hdu 5443 The Water Problem(长春网络赛——暴力)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5443 The Water Problem Time Limit: 1500/1000 MS (Java ...
- Unity的 Stats 窗体, Batched、SetPass、Draw Call 等
孙广东 2015.8.12 在Game View 中的右上角有一个统计数据 Stats button.当按下button时.覆盖窗体显示,可用于优化性能的实时渲染统计信息. 确切的统计数据显示生成目 ...
- ACM计算几何模板——二维几何基础(基本运算,点和线,多边形)
/*==========================*\ | 计算几何基础函数 | | 1.点和向量的定义 | | 2.向量的基本运算 | | 3.点积 | | 4.向量长度 | | 5.两向量角 ...
- Loadrunner测试实例分析
LoadRunner性能测试结果分析是个复杂的过程,通常可以从结果摘要.并发数.平均事务响应时间.每秒点击数.业务成功率.系统资源.网页细分图.Web服务器资源.数据库服务器资源等几个方面分析,如图1 ...
- 全新的membership框架Asp.net Identity——绕不过的Claims
http://www.cnblogs.com/JustRun1983/p/4708176.html?utm_source=tuicool&utm_medium=referral
- Pecan
什么是peacn Pecan是一个轻量级的基于Python的Web框架, Pecan的目标并不是要成为一个“full stack”的框架, 因此Pecan本身不支持类似Session和Database ...
- 杂记之--苹果4s手机呼叫转移怎么设置
您好,呼叫转移只需在拨号界面输入相应的代码就可以,无需其他设置无条件转移 **21*电话号码#再按拨号键 取消代码:##21# *#21# 再按拨号键无信号,关机转移 **62*电话号码#再按拨号键 ...
- Linux中使用SecureCRT上传、下载文件命令sz与rz用法实例
来自:http://www.jb51.net/LINUXjishu/163820.html 其中,对于sz和rz的理解与记忆我用了如下的方法(因为很多时候容易搞混):sz中的s意为send(发送),告 ...
- c#基础 第三讲
Random r = new Random(); string x, y; while (true) { ...
- 设置 SSH Key 登录服务器和 Git 服务器
设置 SSH Key 登录服务器 通过 ssh 登录服务器,一直都是用的账号和密码,今天看到一篇文章说这样不安全,使用 ssh key 的方式登录则是更好的选择,因此,研究实践了一下,并记录在这里. ...