POJ训练计划1035_Spell checker(串处理/暴力)
| Time Limit: 2000MS | Memory Limit: 65536K | |
| Total Submissions: 18418 | Accepted: 6759 |
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
write this word first, then write the character ':' (colon), and after a single space write all its possible replacements, separated by spaces. The replacements should be written in the order of their appearance in the dictionary (in the first part of the
input file). If there are no replacements for this word then the line feed should immediately follow the colon.
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
C++只是,G++过。。
。
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath> using namespace std;
struct node
{
char s[20];
int t;
} dic[10010];
int ctt(char *str,char *ch)
{
int l1=strlen(str),l2=strlen(ch);
int i,t=0;
if(l1<l2)
{
for(i=0;i<l2;i++)
{
if(str[t]==ch[i])
t++;
if(t==l1)
return 1;
}
return 0;
}
else if(l1>l2)
{
for(i=0;i<l1;i++)
{
if(str[i]==ch[t])
t++;
if(t==l2)
return 1;
}
return 0;
}
else
{
for(i=0;i<l1;i++)
{
if(str[i]==ch[i])
t++;
}
if(t==l1-1)
return 1;
else
return 0;
}
}
int main()
{
int n=0,f=0,i;
char str[20];
while(~scanf("%s",str))
{
if(str[0]=='#')break;
strcpy(dic[n].s,str);
dic[n++].t=n;
}
//<<ctt("aware","award");
while(~scanf("%s",str))
{
f=0;
if(str[0]=='#')break;
for(i=0; i<n; i++)
{
if(strcmp(str,dic[i].s)==0)
{
printf("%s is correct",str);
f=1;
break;
}
}
if(!f)
{
printf("%s:",str);
int l=strlen(str);
for(i=0; i<n; i++)
{
if(strlen(dic[i].s)-l==1||strlen(dic[i].s)-l==-1||strlen(dic[i].s)-l==0)
{
if(ctt(str,dic[i].s))
printf(" %s");
}
}
}
printf("\n");
}
}
POJ训练计划1035_Spell checker(串处理/暴力)的更多相关文章
- POJ训练计划3080_Blue Jeans(串处理/暴力)
Blue Jeans Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11542 Accepted: 4962 Descr ...
- POJ 1035 Spell checker(串)
题目网址:http://poj.org/problem?id=1035 思路: 看到题目第一反应是用LCS ——最长公共子序列 来求解.因为给的字典比较多,最多有1w个,而LCS的算法时间复杂度是O( ...
- POJ训练计划
POJ训练计划 Step1-500题 UVaOJ+算法竞赛入门经典+挑战编程+USACO 请见:http://acm.sdut.edu.cn/bbs/read.php?tid=5321 一.POJ训练 ...
- POJ 3294 n个串中至少一半的串共享的最长公共子串
Life Forms Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 12484 Accepted: 3502 Descr ...
- POJ - 3080 Blue Jeans 【KMP+暴力】(最大公共字串)
<题目链接> 题目大意: 就是求k个长度为60的字符串的最长连续公共子串,2<=k<=10 限制条件: 1. 最长公共串长度小于3输出 no significant co ...
- POJ 1159 回文串-LCS
题目链接:http://poj.org/problem?id=1159 题意:给定一个长度为N的字符串.问你最少要添加多少个字符才能使它变成回文串. 思路:最少要添加的字符个数=原串长度-原串最长回文 ...
- POJ 3974 回文串-Manacher
题目链接:http://poj.org/problem?id=3974 题意:求出给定字符串的最长回文串长度. 思路:裸的Manacher模板题. #include<iostream> # ...
- poj 1035 Spell checker
Spell checker Time Limit: 2000 MS Memory Limit: 65536 KB 64-bit integer IO format: %I64d , %I64u J ...
- poj 2187 Beauty Contest (凸包暴力求最远点对+旋转卡壳)
链接:http://poj.org/problem?id=2187 Description Bessie, Farmer John's prize cow, has just won first pl ...
随机推荐
- 落谷p3376 最大流EdmondsKarp增广路模板
参考: https://blog.csdn.net/txl199106/article/details/64441994 分析: 该算法是用bfs求出是否有路从s到t, 然后建立反向边(关于反向边), ...
- python图像插值
最近邻:选择离它所映射到的位置最近的输入像素的灰度值为插值结果. 最临近插值 图像的缩放很好理解,就是图像的放大和缩小.传统的绘画工具中,有一种叫做“放大尺”的绘画工具,画家常用它来放大图画.当然,在 ...
- linux救援
1.单用户模式(类比win的安全模式) 1.1.开机按任意键 1.2.按E进入编辑模式 1.3.光标移动到第二个(“kernel xxxx”)按e 1.4.在quiet 后面输入“ 1” or “S” ...
- jsonp实现跨域访问json数据
前台js function init() { $.ajax({ url: 'http://localhost:8012/index.json', dataType: "jsonp" ...
- redis中redis.conf配置文件
redis.conf文件配置解释 1. Redis默认不是以守护进程的方式运行,可以通过该配置项修改,使用yes启用守护进程 daemonize yes 2. 当Redis以守护进程方式运行时,Red ...
- iOS NSLog各种打印
%@ 对象 %d,%i 整型 (%i的老写法) %hd 短整型 %ld , %lld 长整型 %u 无符整型 %f 浮点型和double型 %0.2f 精度浮点数,只保留两位小数 %x: 为32 ...
- ZipKin原理学习--zipkin支持日志打印追踪信息
目前在zipkin brave已经提供功能在我们使用logback或log4j等时可以在日志信息中将traceId和spanId等信息打印到运行日志,这样可能对我们通过日志查看解决问题有比较大的 ...
- wamp Apache和mysql服务无法启动的终极解决方法!!!!!!
用了几年的wampserver 突然宣告无法启动,Apache和mysql都崩溃了,在计算机的服务选项里面也是无法启动的,系统报了一个未知错误,重装了N个版本的PHP集成开发环境,都宣告失败! 我想应 ...
- Codevs 1021 玛丽卡==洛谷 P1186
时间限制: 2 s 空间限制: 128000 KB 题目等级 : 大师 Master 题目描述 Description 麦克找了个新女朋友,玛丽卡对他非常恼火并伺机报复. 因为她和他们不住在同一个 ...
- HDU 5001 Walk (暴力、概率dp)
Walk Time Limit: 30000/15000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Sub ...