POJ 1035 Spell checker

直接暴力比就可以

C++ Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>

using namespace std;

char dic[10005][20];
char tmp[20];

int main(){
int dic_len = 0;
while(~scanf("%s", dic[dic_len])){
if(dic[dic_len][0] == '#')
break;
dic_len++;
}
while(~scanf("%s", tmp)){
if(tmp[0] == '#')
break;
bool flag = false;
for(int i = 0; i < dic_len; i++){
if(strcmp(tmp, dic[i]) == 0){
printf("%s is correct\n", tmp);
flag = true;
break;
}
}
if(flag == true)
continue;
printf("%s:", tmp);
int tmp_len = strlen(tmp);
for(int i = 0; i < dic_len; i++){
int cnt = 0;
if(tmp_len == strlen(dic[i])){
for(int j = 0; j < tmp_len; j++){
if(tmp[j] != dic[i][j])
cnt++;
}
if(cnt == 1)
printf(" %s", dic[i]);
}else if(tmp_len == strlen(dic[i]) + 1){
for(int j = 0, k = 0; j < strlen(dic[j]) && k < tmp_len; j++, k++){
if(dic[i][j] != tmp[k]){
j--;
cnt++;
}
}
if(cnt <= 1)
printf(" %s", dic[i]);
}else if(tmp_len == strlen(dic[i]) - 1){
for(int j = 0, k = 0; j < strlen(dic[i]) && k < tmp_len; j++, k++){
if(dic[i][j] != tmp[k]){
k--;
cnt++;
}
}
if(cnt <= 1)
printf(" %s", dic[i]);
}
}
printf("\n");
}
return 0;
}