POJ 1035 Spell checker(暴力)
来源:互联网 发布:淘宝开店协议点同意 编辑:程序博客网 时间:2024/06/05 00:23
Spell checker
Time Limit: 2000MS Memory Limit: 65536KTotal Submissions: 22675 Accepted: 8260
Description
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:
?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.
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 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.
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 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
iishashavebemymorecontestmetooifaward#meawaremcontesthavooorifimre#
Sample Output
me is correctaware: awardm: i my mecontest is correcthav: has haveoo: tooor:i is correctfi: imre: more me
点击打开链接
#include<iostream>#include<algorithm>#include<stdio.h>#include<string.h>#include<stdlib.h>#include<math.h>#include<map>using namespace std;char a[10001][100];char b[10001][100];char str[101];int main(){ int h = 0; while(scanf("%s",a[h])) { if(strcmp(a[h],"#") == 0) { break; } h++; } while(scanf("%s",str)) { if(strcmp(str,"#") == 0) { break; } //cout << "str == " << str << endl; int root = 0; int pt = 0; for(int i=0; i<h; i++) { //printf("%d %d\n",str.size(),a[i].size()); int len1 = strlen(str); int len2 = strlen(a[i]); if(abs(len1 - len2)<=1) { //cout << "str == " << str << " 要求 == " << a[i] << endl; int flag = 0; int t = 0; if(len1 == len2) { if(strcmp(str,a[i]) == 0) { root = 1; printf("%s is correct\n",str); break; } else { for(int j=0;j<len1;j++) { if(str[j]!=a[i][j]) { flag++; if(flag == 2) { break; } } } if(flag<=1) { strcpy(b[pt],a[i]); pt++; } } } else if(len1>len2) { t = 0; for(int j=0; j<len1; j++) { if(str[j] == a[i][t]) { t++; } else { flag++; if(flag == 2) { break; } } } if(flag <=1) { strcpy(b[pt],a[i]); pt++; } } else if(len2>len1) { t = 0; for(int j=0; j<len2; j++) { if(str[t] == a[i][j]) { t++; } else { flag++; if(flag == 2) { break; } } } if(flag<=1) { strcpy(b[pt],a[i]); pt++; } } } } if(root == 0) { printf("%s:",str); for(int i=0; i<pt; i++) { printf(" %s",b[i]); } printf("\n"); } } return 0;}
0 0
- poj 1035 Spell checker(暴力判断)
- POJ 1035 Spell checker(暴力)
- poj 1035 Spell checker 字符串,暴力
- POJ 1035 Spell checker【字符串暴力处理】
- POJ 1035 Spell checker 字符串暴力
- POJ 1035 Spell checker 【字符串暴力查找】
- poj 1035 Spell checker &nyoj 162 Spell checker(优化)
- poj-1035-Spell checker
- poj 1035 Spell checker
- Poj 1035 --Spell checker
- Spell checker--POJ 1035
- poj 1035 Spell checker
- poj 1035 Spell checker
- POJ-1035-Spell checker
- poj 1035 Spell Checker
- POJ 1035 Spell checker
- poj 1035 Spell checker
- poj 1035 Spell checker
- awk 两个文件的两个列若相同,合并两个文件
- 225 - Golygons(暴力搜索)
- AFNetworking 同步、异步请求,ios原生支持同步请求
- C语言编程入门——链表
- iOS 去掉系统bar自带的线
- POJ 1035 Spell checker(暴力)
- 剑指offer_面试题9_斐波那契数列
- hdoj 1286找新朋友
- Children of the Candy Corn(POJ--3083
- 覆盖度统计及测试流程
- 南邮 OJ 1024 01排序
- COPY 构建亿级前端读服务
- cocos2dx3.0rc导出自定义类到lua的方法详细步骤
- 7. Document write() 方法