C++代码
  1. /*  
  2. Title: Word Reversal  
  3. Problem URL: http://acm.zju.edu.cn/show_problem.php?pid=1151  
  4. Author: moqi  
  5. Date: 2008-02-08  
  6. Description: Accepted 1151 C++ 00:00.04 392K with Presentation Error * 4  
  7. */  
  8.   
  9. #include <stdio.h>   
  10. #include <string.h>   
  11. int i, lines;   
  12. int total, now;   
  13. char s[250];   
  14. char c;   
  15.   
  16. int main()   
  17. {   
  18. #ifdef ONLINE_JUDGE   
  19. #else   
  20.     freopen("1151.txt""r", stdin);   
  21. #endif   
  22.     scanf("%d", &total);   
  23.     for (now = 0; now < total; now++)   
  24.     {   
  25.         scanf("%d\n", &lines);//IMPORTANT plus \n   
  26.         while (lines– >= 0)   
  27.         {   
  28.             i = 0;   
  29.             while ((c = getchar()) != EOF)   
  30.             {   
  31.                 if (c == ‘ ‘ || c == ‘\n’)   
  32.                 {   
  33.                     while (i– > 0)   
  34.                         putchar(s[i]);   
  35.                     putchar(c);   
  36.                     if (c == ‘\n’)   
  37.                         break;   
  38.                     i = 0;   
  39.                 }   
  40.                 else  
  41.                 {   
  42.                     s[i++] = c;   
  43.                 }   
  44.             }   
  45.         }   
  46.     }   
  47. #ifdef ONLINE_JUDGE   
  48. #else   
  49.     fclose(stdin);   
  50. #endif   
  51.     return 0;   
  52. }