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 ...
随机推荐
- C# 6.0 新特性 (三)
主构造函数 自动属性初始化表达式尤其适合与主构造函数结合使用.主构造函数为降低常见对象模式的繁琐程度提供了一种方法.此功能自五月以来已显著改进.更新包括: 主构造函数的可选实现主体:这将支持此前不受支 ...
- Web开发——服务器端应用技术简单比较
在开发动态网站时,离不开服务器端技术,服务器端技术主要有CGI.ASP.PHP.ASP.NET和JSP. 1.CGI CGI(Common Gateway Interface 通用网关接口)是最早用来 ...
- HDU 6029 Graph Theory
贪心. 每次找到后面最近的一个能连边的连边. #include <bits/stdc++.h> using namespace std; ; int T,n,k; ],b[],u[]; i ...
- Python类总结-封装(Property, setter, deleter)
Property #property #内置装饰器函数,只在面向对象中使用 from math import pi class Circle: def __init__(self,r ): self. ...
- https请求过程
我们都知道HTTPS能够加密信息,以免敏感信息被第三方获取.所以很多银行网站或电子邮箱等等安全级别较高的服务都会采用HTTPS协议. HTTPS简介 HTTPS其实是有两部分组成:HTTP + SSL ...
- Bzoj2510 弱题(矩阵快速幂)
题面(权限题) 题解 一道概率\(dp\),可以设\(f[i][j]\)表示第\(i\)次操作后,标号为\(j\)的小球的期望个数,那么有: \[ \begin{aligned} &f[i][ ...
- export导出.xls时,在火狐的情况下出现表名乱码的情况的解决方案
response.setContentType("application/octet-stream; charset=utf-8");fileName = exportDataDt ...
- Wannafly挑战赛17 B
题解 大概就是求证这个 \[\sum_i^nC_{n}^i*C_n^i = C_{2n}^n\] 证明: \[(1+x)^{2n} = [C(0,n)+C(1,n)*x+...+C(n,n)*x^n] ...
- 「LOJ6482」LJJ爱数数
「LOJ6482」LJJ爱数数 解题思路 : 打表发现两个数 \(a, b\) 合法的充要条件是(我不管,我就是打表过的): \[ a + b = \text{gcd}(a, b)^2 \] 设 \( ...
- luoguP3239 [HNOI2015]亚瑟王 概率期望DP
当初怎么想的来着.....又忘了...... 首先,总期望 = 每张卡片的期望之和 求期望,只要我们求出每张卡片被用掉的概率即可 如果直接上状态$f[i][j]$表示在第$i$轮中,第$j$张牌发动的 ...