C++代码
- /*
- Title: Word Reversal
- Problem URL: http://acm.zju.edu.cn/show_problem.php?pid=1151
- Author: moqi
- Date: 2008-02-08
- Description: Accepted 1151 C++ 00:00.04 392K with Presentation Error * 4
- */
- #include <stdio.h>
- #include <string.h>
- int i, lines;
- int total, now;
- char s[250];
- char c;
- int main()
- {
- #ifdef ONLINE_JUDGE
- #else
- freopen("1151.txt", "r", stdin);
- #endif
- scanf("%d", &total);
- for (now = 0; now < total; now++)
- {
- scanf("%d\n", &lines);//IMPORTANT plus \n
- while (lines– >= 0)
- {
- i = 0;
- while ((c = getchar()) != EOF)
- {
- if (c == ‘ ‘ || c == ‘\n’)
- {
- while (i– > 0)
- putchar(s[i]);
- putchar(c);
- if (c == ‘\n’)
- break;
- i = 0;
- }
- else
- {
- s[i++] = c;
- }
- }
- }
- }
- #ifdef ONLINE_JUDGE
- #else
- fclose(stdin);
- #endif
- return 0;
- }