标签:des style blog http color strong
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 18712 | Accepted: 6856 |
Description
Input
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
字符串的题目,给一个词典,然后判断输入的单词是否在词典中,如果不在,则找长度减一/加一/正好/中的单词且满足只有一个字母不一样,
第一次用LSC做的,可能姿势不对,超时了,直接暴力能过。
1 /*====================================================================== 2 * Author : kevin 3 * Filename : SpellChecker1.cpp 4 * Creat time : 2014-07-19 13:09 5 * Description : 6 ========================================================================*/ 7 #include <iostream> 8 #include <algorithm> 9 #include <cstdio> 10 #include <cstring> 11 #include <queue> 12 #include <cmath> 13 #define clr(a,b) memset(a,b,sizeof(a)) 14 #define M 10005 15 using namespace std; 16 char words[M+10][20]; 17 int cnt; 18 void init() 19 { 20 cnt = 0; 21 while(scanf("%s",words[cnt])){ 22 if(strcmp(words[cnt],"#") == 0){ 23 break; 24 } 25 else cnt++; 26 } 27 } 28 bool judge1(char a[],char b[],int len1,int len2) 29 { 30 int cnt = 0; 31 for(int i = 0; i < len1; i++){ 32 if(a[i] != b[i]) 33 cnt++; 34 } 35 if(cnt == 1) return true; 36 return false; 37 } 38 bool judge2(char a[],char b[],int len1,int len2) 39 { 40 int flag = 0; 41 for(int i = 0; i < len1; i++){ 42 flag = 1; 43 for(int j = 0,k = 0; j < len1 && k < len2; ){ 44 if(j == i){ 45 j++; continue; 46 } 47 if(a[j] != b[k]){ 48 flag = 0; 49 } 50 j++; k++; 51 } 52 if(flag) return true; 53 } 54 return false; 55 } 56 bool judge3(char a[],char b[],int len1,int len2) 57 { 58 int flag; 59 for(int i = 0; i < len2; i++){ 60 flag = 1; 61 for(int j = 0,k = 0; j < len1 && k < len2; ){ 62 if(k == i){ 63 k++; continue; 64 } 65 if(a[j] != b[k]) 66 flag = 0; 67 j++; k++; 68 } 69 if(flag) return true; 70 } 71 return false; 72 } 73 int main(int argc,char *argv[]) 74 { 75 init(); 76 char str[20]; 77 while(scanf("%s",str)){ 78 if(strcmp(str,"#") == 0){ 79 break; 80 } 81 int flag = 0; 82 for(int i = 0; i < cnt; i++){ 83 if(strcmp(words[i],str) == 0){ 84 printf("%s is correct\n",str); 85 flag = 1; 86 break; 87 } 88 } 89 if(!flag){ 90 printf("%s:",str); 91 int len1 = strlen(str); 92 for(int i = 0; i < cnt; i++){ 93 int len2 = strlen(words[i]); 94 if(len1 == len2){ 95 if(judge1(words[i],str,len2,len1)){ 96 printf(" %s",words[i]); 97 } 98 } 99 if(len1+1 == len2){ 100 if(judge2(words[i],str,len2,len1)){ 101 printf(" %s",words[i]); 102 } 103 } 104 if(len1 == len2+1){ 105 if(judge3(words[i],str,len2,len1)){ 106 printf(" %s",words[i]); 107 } 108 } 109 } 110 printf("\n"); 111 } 112 } 113 return 0; 114 }
poj 1035 -- Spell checker,布布扣,bubuko.com
标签:des style blog http color strong
原文地址:http://www.cnblogs.com/ubuntu-kevin/p/3855107.html