题目大意:原题链接

1输入一个字符串,如果字典中存在该字符串,直接输出,否则;

2.删除,替换,或插入一个字母。如果使得输入字符串==字典中已经有的单词,输出该单词,否则。

3.直接输入下一个字符串,继续匹配.

  1. #include<vector>
  2. #include<string>
  3. #include<iostream>
  4. using namespace std;
  5. string s;
  6. int main(){
  7. vector<string> dict;
  8. while(cin>>s){
  9. if(s=="#") break;
  10. dict.push_back(s);
  11. }
  12. while(cin>>s){
  13. if(s=="#") break;
  14. cout<<s;
  15. int len1=s.size();
  16. bool sign=false;
  17. for(int i=;i<dict.size();i++){
  18. if(s==dict[i]){
  19. cout<<" is correct"<<endl;
  20. sign=true;break;
  21. }
  22. }
  23. if(!sign){
  24. cout<<":";
  25. //枚举字典中每一个单词进行查找
  26. for(int i=;i<dict.size();i++){
  27. int len2=dict[i].size();
  28. int d=,delta=len2-len1;
  29. if(delta>||delta<-) continue;
  30. if(delta==-){//删除
  31. for(int j=;j<len1;j++){
  32. if(s[j]==dict[i][d])
  33. d++;
  34. }
  35. if(d==len2) cout<<' '<<dict[i];
  36. }
  37. else if(delta==){//替换
  38. for(int j=;j<len1;j++){
  39. if(s[j]!=dict[i][j])
  40. d++;
  41. }
  42. if(d==) cout<<' '<<dict[i];
  43. }
  44. else if(delta==){//插入
  45. for(int j=;j<len2;j++){
  46. if(s[d]==dict[i][j])
  47. d++;
  48. }
  49. if(d==len1) cout<<' '<<dict[i];
  50. }
  51. }
  52. cout<<endl;
  53. }
  54. }
  55. }

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. List去重复(List中存的是对象)

    class ProductComparare : IEqualityComparer<YEWULIANG> { private Func<YEWULIANG, object> ...

  2. Ubuntu16.04 Tomcat9的安装

    1. 从http://tomcat.apache.org/download-90.cgi 下载apache-tomcat-9.0.0.M11.tar.gz 2. 上传到Linux后移动到/opt/to ...

  3. hdu 1233:还是畅通工程(数据结构,图,最小生成树,普里姆(Prim)算法)

    还是畅通工程 Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submis ...

  4. angularJs 多文件动态上传(删除其中一个文件的时候,要么file没被删除,要么删除了之后,点击事件失效)

    <div cacModule.controller('CacScriptEditCtrl', CacScriptEditCtrl); CacScriptEditCtrl.$inject = [' ...

  5. hdu4734(记忆化搜索)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4734 思路:记忆化搜索. #include<iostream> #include<c ...

  6. 一稿设计多端适配优雅的解决方案 - rem

    规范目的 为提高前端团队开发效率,输出高质量的前端页面代码,提高UI设计还原度,特编写该规范文档.本文档如有不对或者不合适的地方请及时提出. JS代码块 (function (doc, win) { ...

  7. 分页技巧__在项目中使用QueryHelper辅助对象实现分页效果

    分页技巧__在项目中使用QueryHelper辅助对象实现分页效果 QueryHelper 用于辅助拼接HQL语句 addCondition("t.type=?", "精 ...

  8. pushViewController自定义动画http://blog.csdn.net/ralbatr/article/details/22039233

     本文转载至  http://blog.csdn.net/ralbatr/article/details/22039233 实现的主要代码如下: CATransition *transition =  ...

  9. 在Hyper-V Linux VM如何选择LIS Linux集成服务

    导读 很多工程师都知道,如果你选择在 Hyper-V 中运行 Linux guest VM,要获得最好的使用体验,必需针对你所使用的 Linux 发行版和使用场景选择 Linux Integratio ...

  10. 如何把IOS应用,发给别人测试?

    ios应用,除了用XCODE连接真实设备调试以外,也可以制作ipa安包,发给别人测试.下面是具体步骤: 1. 把要测试的设备标识添加到你苹果开发账号的调试设备里.(可以用xcode或者itools查看 ...