短小而精悍的代码,把我所学的几乎都用上了,测试数据过了,只可惜不AC,挣扎了一天了,累死啦!!!!!
View Code
#include<stdio.h> #include<string.h> #include<stdlib.h> #include<ctype.h> int cmp(const void *a,const void *b) { return strcmpi((char *)a,(char *)b); } char word[210][17],iword[51][17],st[10002]; int main() { int itop = 0, top = 0, i = 0, j = 0, k = 1, s[10001] = {0}, t = 0, r; char ch; while(gets(iword[itop])) { if(strcmp(iword[itop],"::") == 0) break; itop++; } while((ch = getchar()) != EOF) { t++; if(ch != '\n') st[i++] = ch; if(ch != ' ' && ch != '\n') word[top][j++] = ch; else { word[top][j] = '\0'; top++; for(r = 0;r < itop; r++) { if(strcmpi(iword[r],word[top-1]) == 0) { top--; break; } } j = 0; if(ch == '\n') { st[i++] = '\0'; s[k++] = t; } } } qsort(word,top,sizeof(word[0]),cmp); for(j = 0;j < top; j++) { int len = strlen(word[j]), x = 0; if(strcmpi(word[j],word[j+1]) == 0) { continue; } for(r = 0;r < k; r++) { x = 0; while(strstr(st+s[r]+x,word[j]) != NULL) { char *p = strstr(st+s[r]+x,word[j]), *q; x = p - st+len; for(q = st+s[r];q < p; q++) { if(isalpha(*q)) putchar(tolower(*q)); else putchar(*q); } for(;q < p+len; q++) putchar(toupper(*q)); for(;*q != '\0';q++) { if(isalpha(*q)) putchar(tolower(*q)); else putchar(*q); } puts(""); } } } return 0; }