Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
求测试数据,代码如下#include <stdio.h> #include <string.h> #include <vector> #include <algorithm> using namespace std; typedef struct { char name[15]; int num; }Word; struct { int count; Word word[10000+10]; }dic[15+1]; vector <Word> result; bool Comp(const Word &a, const Word &b) { return a.num<b.num; } int exist(char word[], int length) { int i; for (i=0; i<dic[length].count; i++) if (strcmp(dic[length].word[i].name, word) == 0) return 1; return 0; } int del(char word[], int length) { if (length == 15) return 0; int i, j, k, flag = 0; char dicWord[15]; Word _word; for (i=0; i<dic[length+1].count; i++) { strcpy(dicWord, dic[length+1].word[i].name); for (j=0, k=0; j<strlen(dicWord); j++) if (dicWord[j] == word[k]) k++; if (k == length) { strcpy(_word.name, dicWord); _word.num = dic[length+1].word[i].num; result.push_back(_word); //printf(" %s", dicWord); flag++; } } if (flag) return 1; else return 0; } int insert(char word[], int length) { if (length == 1) return 0; int i, j, k, flag = 0; char dicWord[15]; Word _word; for (i=0; i<dic[length-1].count; i++) { strcpy(dicWord, dic[length-1].word[i].name); for (j=0, k=0; j<length; j++) if (word[j] == dicWord[k]) k++; if (k == strlen(dicWord)) { strcpy(_word.name, dicWord); _word.num = dic[length-1].word[i].num; result.push_back(_word); //printf(" %s", dicWord); flag++; } } if (flag) return 1; else return 0; } int replace(char word[], int length) { int i, j, differ = 0, flag = 0; char dicWord[15]; Word _word; for (i=0; i<dic[length].count; i++) { strcpy(dicWord, dic[length].word[i].name); for (j=0; j<length; j++) if (dicWord[j] != word[j]) differ++; if (differ == 1) { strcpy(_word.name, dicWord); _word.num = dic[length].word[i].num; result.push_back(_word); //printf(" %s", dicWord); flag++; } } if (flag) return 1; else return 0; } int main() { char word[15]; int length, count = 0, num = 0; while (scanf("%s", word) && word[0] != '#') { length = strlen(word); strcpy(dic[length].word[dic[length].count].name, word); dic[length].word[dic[length].count++].num = num++; } while (scanf("%s", word) && word[0] != '#') { length = strlen(word); if (exist(word, length)) { printf("%s is correct\n", word); continue; } printf("%s:", word); insert(word, length); replace(word, length); del(word, length); if (!result.empty()) { sort(result.begin(), result.end(), Comp); vector <Word>::iterator it; for (it=result.begin(); it!=result.end(); it++) printf(" %s", (*it).name); } result.clear(); printf("\n"); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator