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 ...
随机推荐
- php如何发起POST DELETE GET POST 请求
关于POST,DELETE,GET,POST请求 get:是用来取得数据.其要传递过的信息是拼在url后面,因为其功能使然,有长度的限制 post:是用来上传数据.要上传的数据放在request的he ...
- windows下php连接sqlserver2008
如果你需要和sql server通信需要到http://msdn.microsoft.com/en-us/sqlserver/ff657782.aspx自行下载微软提供的The SQL Server ...
- Mac截图快捷键
Shift+Command+3 截取全屏幕至桌面 Shift+Command+4 截取部分屏幕至桌面 Shift+Command+4+空格 截取窗口或原件至桌面 Shift+Command+4 然后E ...
- wtforms 使用
wtforms是一个表单模板库, 下面以修改密码表单为例简单说明其用法. 我们可以用python代码定义form的基本元素, 比如用户名/邮箱, 并给定各个元素的validation条件. 然后在re ...
- Reading Famous blog to prevent me wasting time on blind wandering
I can`t help surfing the useless bbs and some other kind of SNS. The time I begin to do it, it costs ...
- Todd's Matlab讲义第4讲:控制误差和条件语句
误差和残量 数值求解方程\(f(x)=0\)的根,有多种方法测算结果的近似程度.最直接的方法是计算误差.第\(n\)步迭代结果与真值\(x^\*\)的差即为第\(n\)步迭代的误差: \begin{e ...
- firefox浏览器不能使用window.close的解决方案
javascript中window.close()函数用来关闭窗体,而且IE.google.firefox浏览均支持,但由于firefox浏览器dom.allow_scripts_to_close_w ...
- Java并发包源码学习之AQS框架(三)LockSupport和interrupt
接着上一篇文章今天我们来介绍下LockSupport和Java中线程的中断(interrupt). 其实除了LockSupport,Java之初就有Object对象的wait和notify方法可以实现 ...
- XH
1. 又到父亲节,那就给老爹做顿饭呗,让他开心开心. 老爸吃了一口我炒的菜,流露出感动的泪花说:儿呀,你能为爸爸做饭,爸爸感到特别开心,但是你这个菜,看在今天是父亲节 我能不能不吃呀! 2. 一哥 ...
- 一个C#的与web服务器交互的HttpClient类
using System; using System.Collections.Generic; using System.IO; using System.Text; using System.Net ...