http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=59
每输入一个句子,将不被忽略的词(not to ignore)及其所在位置保存下来,然后对所有这样的词排序,输出即可。
# include <stdio.h> # include <string.h> # include <ctype.h> # include <stdlib.h> int n, m; char ignored[55][15]; char s[205][1005]; int wn; char words[2005][25]; int pr[2005]; int pc[2005]; int r[2005]; bool exist(char *str) { for (int i = 0; i < n; ++i) { if (strcmp(str, ignored[i]) == 0) return true; } return false; } int icmp(const void *x, const void *y) { return strcmp( words[*(int*)x], words[*(int*)y] ); } int main() { n = 0; while (1) { gets(ignored[n]); if (strcmp(ignored[n], "::") == 0) break; ++n; } m = 0; wn = 0; while (gets(s[m]) != NULL) { for (int i = 0; s[m][i]; ++i) s[m][i] = tolower(s[m][i]); for (int i = strlen(s[m])-1; s[m][i]==' '; --i) s[m][i] = '