nefu1039超级超级简单的英文题==
2015-09-21 21:11
337 查看
description |
[code] You, as a member of a development team for a new spell checking program, are to write a module that will check the correctness of given words using a known dictionary of all correct words in all their forms. 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: (1)deleting of one letter from the word; (2)replacing of one letter in the word with an arbitrary letter; (3)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 first part of the input file contains all words from the dictionary. Each word occupies its own line. This part is finished by the single character '#' on a separate line. All words are different. There will be at most 10000 words in the dictionary. 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. |
input |
[code] The first part of the input file contains all words from the dictionary. Each word occupies its own line. This part is finished by the single character '#' on a separate line. All words are different. There will be at most 10000 words in the dictionary. 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 |
[code] Write to the output file exactly one line for every checked word in the order of their appearance in the second part of the input file. If the word is correct (i.e. it exists in the dictionary) write the message: " is correct". If the word is not correct then 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 |
sample_input |
[code] i is has have be my more contest me too if award # me aware m contest hav oo or i fi mre # |
sample_output |
[code] 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 |
#include <iostream> #include<cstring> #include<cstdio> using namespace std; char dict[10005][30],check[100][30]; char tmp[30]; int main() { // freopen("data.in.txt","r",stdin); //freopen("data.out.txt","w",stdout); int i=0; while(cin>>tmp&&tmp[0]!='#') { strcpy(dict[i],tmp); i++; } int j=0,mark; while(cin>>tmp&&tmp[0]!='#') { mark=0; for(int k=0;k<i;k++) { if(strcmp(tmp,dict[k])==0) { printf("%s is correct\n",tmp); mark=1; break; } } if(mark==1) { mark==0; continue; } int c=strlen(tmp); printf("%s: ",tmp); for(int k=0;k<i;k++) { int d=strlen(dict[k]); if(c-1==d) { int sum=0,p=0; for(int q=0;q<c;q++) { if(tmp[q]==dict[k][p]) p++; //else q--; } if(p==d) { printf("%s ",dict[k]); } } else if(c==d) { int sum=0; for(int q=0;q<c;q++) { if(tmp[q]==dict[k][q]) sum++; } if(sum==c-1) { printf("%s ",dict[k]); } } else if(c+1==d) { int sum=0,p=0; for(int q=0;q<d;q++) { if(tmp[p]==dict[k][q]) p++; //else p--; } if(p==c) { printf("%s ",dict[k]); } } } printf("\n"); } return 0; }
相关文章推荐
- 进程间通信
- 数据库的三大范式
- 【转】django的ORM操作数据库样例
- bugFree环境搭建 及 bugFree环境搭建常见问题
- 在iOS 8中使用UIAlertController
- QTbutton设置背景颜色和文字显示位置设置
- ADRCI
- IOS几种常见的实现扫描、生成二维码的方式(一、使用ZBar SDK)
- 附加数据库失败5120
- jsp中的stl标签库
- XAMPP和VMware Workstation占用443端口冲突的解决办法
- 第 十 一 天 : 复 习 完 ( 四 )
- CentOS 7.1 安装ntfs-3g
- MDT 2013 Update 1 re-released (build 8298)发布
- 关于输入输出的感想
- 关于我的兼职创业历程
- HDU 5464Clarke and problem
- Android与服务器交互
- 第一章,Java语言
- sourceTree拉取远程代码之后报错,说此文件已经删除怎么解决