这道题TLE了N多次,完全不明白为什么,稍微改了一下,居然过了。使用gets过的,看讨论帖有人还推荐用hash。
1 #include <stdio.h> 2 #include <string.h> 3 4 #define LOCAL 0 5 #define MAXNUM 5005 6 #define isSpace(ch) (ch==' '||ch==' '||ch==' ') 7 8 char stand[MAXNUM]; 9 char data[MAXNUM]; 10 char word[MAXNUM]; 11 12 int main() { 13 int n, len1, len2, i, j, flg; 14 #if LOCAL 15 FILE *fout = fopen("data", "w"); 16 #endif 17 scanf("%d%*c", &n); 18 19 while (n--) { 20 scanf("%*s%*c"); // START 21 len1 = 0; 22 while (1) { 23 if (gets(word) == NULL) { 24 stand[len1++] = ' '; 25 continue; 26 } 27 if ( !strcmp(word, "END") ) 28 break; 29 strcpy(stand+len1, word); 30 len1 += strlen(word); 31 stand[len1++] = ' '; 32 } 33 stand[len1++] = '