poj 1035 Spell checker ( 字符串处理 )
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 16675 | Accepted: 6087 |
Description
If the word is absent in the dictionary then it can be replaced by correct words (from the dictionary) that can be obtained by one of the following operations:
?deleting of one letter from the word;
?replacing of one letter in the word with an arbitrary letter;
?inserting of one arbitrary letter into the word.
Your task is to write the program that will find all possible replacements from the dictionary for every given word.
Input
The next part of the file contains all words that are to be checked. Each word occupies its own line. This part is also finished by the single character '#' on a separate line. There will be at most 50 words that are to be checked.
All words in the input file (words from the dictionary and words to be checked) consist only of small alphabetic characters and each one contains 15 characters at most.
Output
Sample Input
i
is
has
have
be
my
more
contest
me
too
if
award
#
me
aware
m
contest
hav
oo
or
i
fi
mre
#
Sample Output
me is correct
aware: award
m: i my me
contest is correct
hav: has have
oo: too
or:
i is correct
fi: i
mre: more me
Source
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std; char dict[10005][20];
char word[55][20];
int dictnum,wordnum; void Input()
{
while(scanf("%s",&dict[dictnum])&&dict[dictnum++][0]!='#');
while(scanf("%s",&word[wordnum])&&word[wordnum++][0]!='#');
dictnum--; //剔除“#”
wordnum--;
} bool Change(char *dict,char *word)
{
int dif=0;
while(*word)
{
if(*(word++)!=*(dict++))
{
dif++;
if(dif>1)
return false;
}
}
return true;
} bool Add(char *dict,char *word)
{
int dif=0;
while(*dict)
{
if(*dict!=*word)
{
dict++;
dif++;
if(dif>1)
return false;
}
else
{
dict++;
word++;
}
}
return true;
} bool Del(char *dict,char *word)
{
int dif=0;
while(*word)
{
if(*word!=*dict)
{
word++;
dif++;
if(dif>1)
return false;
}
else
{
word++;
dict++;
}
}
return true;
} int main()
{
Input();
int *dictlen=new int[dictnum];
for(int i=0;i<dictnum;i++)
dictlen[i]=strlen(dict[i]);
for(int j=0;j<wordnum;j++)
{
int len=strlen(word[j]);
int *address=new int[dictnum];
int pa=0;
int flag=false; for(int k=0;k<dictnum;k++)
{
if(len==dictlen[k])
{
if(strcmp(dict[k],word[j])==0)
{
flag=true;
break;
}
else if(Change(dict[k],word[j]))
address[pa++]=k;
}
else if(len-dictlen[k]==1)
{
if(Del(dict[k],word[j]))
address[pa++]=k;
}
else if(dictlen[k]-len==1)
{
if(Add(dict[k],word[j]))
address[pa++]=k;
}
}
if(flag)
printf("%s is correct\n",word[j]);
else
{
printf("%s: ",word[j]);
for(int d=0;d<pa;d++)
printf("%s ",dict[address[d]]);
printf("\n");
}
delete address;
}
return 0;
}
poj 1035 Spell checker ( 字符串处理 )的更多相关文章
- POJ 1035 Spell checker 字符串 难度:0
题目 http://poj.org/problem?id=1035 题意 字典匹配,单词表共有1e4个单词,单词长度小于15,需要对最多50个单词进行匹配.在匹配时,如果直接匹配可以找到待匹配串,则直 ...
- poj 1035 Spell checker
Spell checker Time Limit: 2000 MS Memory Limit: 65536 KB 64-bit integer IO format: %I64d , %I64u J ...
- [ACM] POJ 1035 Spell checker (单词查找,删除替换添加不论什么一个字母)
Spell checker Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 18693 Accepted: 6844 De ...
- 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(hash)
题目链接:http://poj.org/problem?id=1035 思路分析: 1.使用哈希表存储字典 2.对待查找的word在字典中查找,查找成功输出查找成功信息 3.若查找不成功,对word增 ...
- 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> ]; ][], ...
- POJ1035——Spell checker(字符串处理)
Spell checker DescriptionYou, as a member of a development team for a new spell checking program, ar ...
随机推荐
- python通过帐号和密码访问mysql
数据库:test1 数据表:a1 用input输入姓名和密码,对了的话显示信息.不对的话显示error import pymysql import hashlib conn = pymysql.co ...
- centOS7.0配置防火墙
之前用的iptables来管理的防火墙,后来发现centOS7.0中已经用firewalld取代iptables了,于是与时俱进,停用了iptables. systemctl stop iptable ...
- HDU 6185 Covering
矩阵快速幂. 一开始的思路是$dfs$出一个矩阵,$k[i][j]$表示这一行是状态$i$,将这一行填满,下一行是$j$状态的方案数.然后就可以矩阵快速幂了,但是矩阵大小是$16*16$的,超时了.. ...
- linux——(5)文件与文件系统的压缩与打包
概念一:常见的压缩文件拓展名 .z compress程序压缩的文件. .gz gzip程序压缩的文件. .bz2 bzip2程序压缩的文件. .tar tar程序打包的数据,并没有压缩过. .tar. ...
- FastReport.Net使用:[32]对话框使用2
方法/步骤 1.先浏览下数据,成绩表中有部分科目成绩没有,如果是这种情况,报表是不能打印的. 2.添加一个对话框,将其Visible属性设置为False,默认情况下改对话框是不显示的. 将确定按钮的D ...
- codevs 2181 田忌赛马
2181 田忌赛马 时间限制: 1 s 空间限制: 32000 KB 题目等级 : 钻石 Diamond 题目描述 Description 中国古代的历史故事“田忌赛马”是为大家所熟知的.话说齐王 ...
- luoguP3600 随机数生成器 期望概率DP + DP优化
这篇题解更像对他人题解的吐槽和补充? 考虑答案 $E[X] = \sum\limits_{i = 1}^{x} i P(X = i)$ $P(X = i)$不好求................(其实 ...
- BZOJ 2428 JZYZOJ1533 : [HAOI2006]均分数据 模拟退火 随机化
http://www.lydsy.com/JudgeOnline/problem.php?id=2428 http://172.20.6.3/Problem_Show.asp?id=1533 http ...
- Pollard-rho算法:模板
#include<algorithm> #include<cstdio> #include<cstdlib> #define N 5500 using namesp ...
- Java并发(十五):并发工具类——信号量Semaphore
先做总结: 1.Semaphore是什么? Semaphore(信号量)是用来控制同时访问特定资源的线程数量,它通过协调各个线程,以保证合理的使用公共资源. 把它比作是控制流量的红绿灯,比如XX马路要 ...