poj 1035
http://poj.org/problem?id=1035
poj的一道字符串的水题,不难,但就是细节问题我也wa了几次
题意就是给你一个字典,再给你一些字符,首先如果字典中有这个字符串,则直接输出,如果没有的话,那就找字符串加一个字符或少一个字符或者换一个字符是否可以在字典中找到相应的字符串
解题思路:我是用string类型的,比较方便看两个字符串是否相等,用char的话,就是strcmp函数也行。
如果找不到相等的,那么久分别在字典中找到与这个字符串的长度相差1的或者相等的。
然后匹配,如果匹配的结果相差一个则输出
- #include <stdio.h>
- #include <string.h>
- #include <string>
- #include <iostream>
- #include <stdlib.h>
- using namespace std;
- string str[],str1[];
- int main()
- {
- int dic=,need=;
- while(cin>>str[dic]){
- if(str[dic]=="#") break;
- dic++;
- }
- while(cin>>str1[need]){
- if(str1[need]=="#") break;
- need++;
- }
- //qsort(str,dic,sizeof(str[0]),cmp); //没用的,最开始我是以为要对字典排序输出,其实并不用
- for(int i=;i<need;i++){
- int flog=; //标记,如果找得到相同的字符串,则continue。
- for(int j=;j<dic;j++){
- if(str1[i]==str[j]) {
- cout<<str1[i]<<" is correct"<<endl;
- flog=;
- break;
- }
- }
- if(flog==) continue;
- int len=str1[i].size();
- cout<<str1[i]<<":";
- for(int j=;j<dic;j++){
- int strl=str[j].size();
- if(strl==len||strl==len+||strl==len-){ //字符串相差1的或者相等的,就用来匹配是否有可能相差一个字符,这是一种减枝的办法。
- int ans=;
- if(len>strl){ //吧那个较长的字符作为被匹配的,用短的来匹配长的字符串。
- for(int m=,d=;m<len;m++){
- if(str1[i][m]==str[j][d]){
- ans++;
- d++;
- }
- }
- }else if(len<strl){
- for(int m=,d=;m<strl;m++){
- if(str[j][m]==str1[i][d]){
- ans++;
- d++;
- }
- }
- }else if(len==strl){
- for(int m=,d=;m<strl;m++,d++)
- if(str[j][m]==str1[i][d]) ans++;
- }
- if(len>=strl&&ans==len-) cout<<" "<<str[j];
- if(len<strl&&ans==len) cout<<" "<<str[j];
- }
- }
- cout<<endl;
- }
- return ;
- }
poj 1035的更多相关文章
- POJ 1035 代码+具体的目光
Spell checker Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 19319 Accepted: 7060 Descri ...
- poj 1035 Spell checker(水题)
题目:http://poj.org/problem?id=1035 还是暴搜 #include <iostream> #include<cstdio> #include< ...
- poj 1035 Spell checker(hash)
题目链接:http://poj.org/problem?id=1035 思路分析: 1.使用哈希表存储字典 2.对待查找的word在字典中查找,查找成功输出查找成功信息 3.若查找不成功,对word增 ...
- 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 ( 字符串处理 )
Spell checker Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 16675 Accepted: 6087 De ...
- 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
题 题意 每个单词,如果字典里存在,输出”该单词 is correct“:如果字典里不存在,但是可以通过删除.添加.替换一个字母得到字典里存在的单词,那就输出“该单词:修正的单词”,并按字典里的顺序输 ...
- Spell checker(poj 1035)
题意: 此题是一个字符串的问题,首先要给出一个字典,里面存储了数个单词.而后,给出一个单词,如果字典中存在,那么就输出correct,如果字典中没有,那么就要判断是不是这个单词有错误,错误有3 ...
随机推荐
- mssql注入
<%@ Page Language="C#" AutoEventWireup="true" %> <%@ Import Namespace=& ...
- Effective Objective-C 2.0 — 第三条:多用字面量语法,少用与之等价的方法
第三条:多用字面量语法,少用与之等价的方法 几个类:NSString NSNumber NSArray NSDictionary 字面量语法是一种语法糖(syntactic sugar) NSS ...
- HBase命令(二) -- 表操作
创建表 hbase shell> create 'mytable','col1','col2' //建表语句 create '表名','列簇名','列簇名','列簇名' hbase shell& ...
- RabbitMQ 用户角色详解
RabbitMQ的用户角色分类:none.management.policymaker.monitoring.administrator RabbitMQ各类角色描述:none不能访问 managem ...
- jquery插件写法
//传统写法 //全局方法 ;(function($){ $.method = function(){ } //or $.obj = { method1:function(){}, method2:f ...
- angular-ngSanitize模块-$sanitize服务详解
本篇主要讲解angular中的$sanitize这个服务.此服务依赖于ngSanitize模块. 要学习这个服务,先要了解另一个指令: ng-bing-html. 顾名思义,ng-bind-html和 ...
- rose中设置组合
1.在工具栏选择 "association" (关联).2.编辑role B 属性 open specital , role B detail ,multiplic(重数) 为1, ...
- 记录在xx公司被考核的15天及自己的感想
在大学有两件事让我很遗憾. 第一:在2013年7月我和自己的前任女朋友分手,这是两年前的事了,我们谈了七个月. 第二:在2015年4月我被xx公司淘汰了,正如我的前任女朋友是我遇到的最好女孩,这家公司 ...
- 腾讯web前端笔试题及个人答案
每道题都有答案,大多数答案亲测正确. 简答题 1.js中“5”+4=? 答案:54 2.js中void(0)=? 答案:undefined 3.js中NaN*4=? 答案:NaN 4.js中null* ...
- ACM_1 大数求和
/*1 *2014.11.18 *大数求和 */ #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <strin ...