#include #include #include char tmp[100]; char words[10000][100]; int w; char *readRow(FILE *f){ int i,j; j = 0; for(i = 0; i < 99; ++i) tmp[i] = 0; while(((i = fgetc(f)) != '\n') && (i != -1)) tmp[j++] = i; return tmp; } int readInt(FILE *f){ return atoi(readRow(f)); } int correct(char *word){ int i; for(i = 0; i < w; i++) if(!strcmp(words[i], word)) return 1; return 0; } int missing(char *word,char *w2){ int j, k; char t[101]; t[0] = 0; for(j = 0; j < strlen(word); j++){ for(k = 0; k < 26; k++){ strcpy(t, word); t[j] = ('a' + k); strcpy(t + j + 1, word + j); if(!strcmp(t,w2)){ strcpy(tmp, t); return 2; } } } return 0; } int toomuch(char *word, char *w2){ int i; char t[101]; t[0] = 0; for(i = 0; i < strlen(word); ++i){ strcpy(t, word); strcpy(t + i, t + i + 1); if(!strcmp(t,w2)){ strcpy(tmp,t); return 2; } } return 0; } int wrongletter(char *word, char *w2){ int i,j; char t[101]; for(i = 0; i < strlen(word); ++i){ strcpy(t, word); for(j = 0; j < 26; j++){ t[i] = ('a' + j); if(!strcmp(t,w2)){ strcpy(tmp,t); return 2; } } } return 0; } int wrongorder(char *word, char *w2){ int i; char t[101]; char c; for(i = 0; i < (strlen(word) - 1); i++){ strcpy(t, word); c = t[i]; t[i] = t[i +1]; t[i + 1] = c; if(!strcmp(t, w2)){ strcpy(tmp,t); return 2; } } return 0; } void checkWord(char *word){ int res = 0; int i; char cword[100]; strcpy(cword, word); res |= correct(word); for(i = 0; i < w; i++){ if(res == 0) res |= missing(word, words[i]); if(res == 0) res |= toomuch(word, words[i]); if(res == 0) res |= wrongletter(word, words[i]); if(res == 0) res |= wrongorder(word, words[i]); } if(res & 1){ printf("%s is correct\n", cword); return; } if(res & 2){ printf("%s is a misspelling of %s\n", cword, word); return; } printf("%s is unknown\n", cword); } int main(int argc, char **argv){ char *t; int i,j; FILE *f; f = fopen("automatic.in", "r"); w = readInt(f); for(j = 0; j < w; j++){ strcpy(words[j], readRow(f)); } i = readInt(f); for(j = 0; j < i; j++) checkWord(readRow(f)); return 0; }