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> ]; ][], ...
随机推荐
- CSS之各种居中
本博客讨论居中情况设定为 总宽度不定,内容宽度不定 的情况.(改变大小时,仍然居中). 特别说明:在元素设置 position:absolute; 来设置居中效果时,除去博客下介绍的css3方法外,还 ...
- 系统管理模块_部门管理_改进_抽取添加与修改JSP页面中的公共代码_在显示层抽取BaseAction_合并Service层与Dao层
系统管理模块_部门管理_改进1:抽取添加与修改JSP页面中的公共代码 commons.jspf <%@ page language="java" import="j ...
- iOS开发之--改变系统导航的颜色,字体,还有返回样式的自定义
在写项目的工程中,我们可能会遇到各种各样的项目,写的方法也是各有不同,不喜欢自定义的小伙伴也很多, 下面我就记录下系统导航和barbuttonitem的修改系统空间的方法: 1,添加rightbarb ...
- poj 1386
Play on Words Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 11312 Accepted: 3862 De ...
- Microsoft License Keys – Volume
VLK Product Group Product KeyOffice XP Applications P3HBK-F86Y2-374PQ-KW92R-B36VTOffice 2003 Suites ...
- 160616、jQuery插件之ajaxFileUpload及jqueryeasyui学习资料分享
第一步:先引入jQuery与ajaxFileUpload插件.注意先后顺序,ajaxFileUpload插件依赖jquery <script src="${base}/mobile/j ...
- ThreadLocal分析总结:
1.ThreadLocal 是什么 它是一个数据结构,像 HashMap,可保存 "key : value" 键值对:ThreadLocal 有一个内部类ThreadLocalMa ...
- HDU 5876 大连网络赛 Sparse Graph
Sparse Graph Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) T ...
- 浅析Android View(二)
深入理解Android View(一) View的位置參数信息 二.View的绘制过程 View的绘制过程一共分为三个部分: - measure(測量View的大小) - layout(确定View的 ...
- JSR303验证
转自:http://blog.csdn.net/lu930124/article/details/52587135 JSR-303是一个数据验证的规范,这里我不会讲这个规范是怎么回事,只会讲一下JSR ...