题目大意:原题链接

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应用)的更多相关文章

  1. poj 1035 Spell checker

    Spell checker Time Limit: 2000 MS Memory Limit: 65536 KB 64-bit integer IO format: %I64d , %I64u   J ...

  2. poj 1035 Spell checker ( 字符串处理 )

    Spell checker Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 16675   Accepted: 6087 De ...

  3. [ACM] POJ 1035 Spell checker (单词查找,删除替换添加不论什么一个字母)

    Spell checker Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 18693   Accepted: 6844 De ...

  4. POJ 1035 Spell checker 字符串 难度:0

    题目 http://poj.org/problem?id=1035 题意 字典匹配,单词表共有1e4个单词,单词长度小于15,需要对最多50个单词进行匹配.在匹配时,如果直接匹配可以找到待匹配串,则直 ...

  5. POJ 1035 Spell checker(串)

    题目网址:http://poj.org/problem?id=1035 思路: 看到题目第一反应是用LCS ——最长公共子序列 来求解.因为给的字典比较多,最多有1w个,而LCS的算法时间复杂度是O( ...

  6. poj 1035 Spell checker(水题)

    题目:http://poj.org/problem?id=1035 还是暴搜 #include <iostream> #include<cstdio> #include< ...

  7. 【POJ】1035 Spell checker

    字典树. #include <iostream> #include <cstdio> #include <cstring> #include <cstdlib ...

  8. POJ 1035 Spell checker (模拟)

    题目链接 Description You, as a member of a development team for a new spell checking program, are to wri ...

  9. POJ 1035 Spell checker 简单字符串匹配

    在输入的单词中删除或替换或插入一个字符,看是否在字典中.直接暴力,172ms.. #include <stdio.h> #include <string.h> ]; ][], ...

随机推荐

  1. 学习:java代码检测

    转自:http://zh.wikipedia.org/wiki/%E4%BB%A3%E7%A0%81%E5%BC%82%E5%91%B3 对于Java开发语言,有些工具,比如Checkstyle.PM ...

  2. 学习:record用法

    详情请参考官网:http://www.erlang.org/doc/reference_manual/records.html http://www.erlang.org/doc/programmin ...

  3. shell命令技巧——文本去重并保持原有顺序

    简单来说,这个技巧相应的是例如以下一种场景 假设有文本例如以下 cccc aaaa bbbb dddd bbbb cccc aaaa 如今须要对它进行去重处理.这个非常easy,sort -u就能够搞 ...

  4. 10条建议帮助你创建更好的jQuery插件

    本文总结了帮助你创建更好jQuery插件的10条建议.分享给大家供大家参考.具体说明如下: 在开发过很多 jQuery 插件以后,我慢慢的摸索出了一套开发jQuery插件比较标准的结构和模式.这样我就 ...

  5. python定义函数时的默认返回值

    python定义函数时,一般都会有指定返回值,如果没有显式指定返回值,那么python就会默认返回值为None, 即隐式返回语句: return None 执行如下代码 def now(): prin ...

  6. Tanks案例笔记(一、场景搭建)

    一.场景搭建 1.首先我们导入案例的资源,然后新建一个空场景: 2.资源中为我们准备的场景的预制,我们直接把LevelArt预制拖到Hierarchy面板: 3.移除场景中默认的光源: 4.确保物体的 ...

  7. IOC和AOP的一些基本概念

    IOC和AOP的一些基本概念介绍 IOC 介绍 IOC 一.什么是IOC IoC就是Inversion of Control,控制反转.在Java开发中,IoC意味着将你设计好的类交给系统去控制,而不 ...

  8. MyEclipse10.6 安装SVN插件方法及插件下载地址

        今天MyEclipse10.6出了点问题,所以重装了它,同一时候也把svn的插件重装了一次,把网上资源和自己的经历顺便在博客这里记录一下.建议直接看方法一好了,简单方便,不必要折腾太多. 下来 ...

  9. Android下在onCreate中获取控件的宽度和高度(通过回调)

    有时候需要在onCreate方法中知道某个View组件的宽度和高度等信息, 而直接调用View组件的getWidth().getHeight().getMeasuredWidth().getMeasu ...

  10. jquery remove() detach() empty()三种方法的区别

    remove方法把事件删除掉了,数据并没有删除 detach方法保存了事件和数据 empty方法保留了元素本身,移除子节点,删除内容 举例: <!DOCTYPE html><html ...