UVa 483 - Word Scramble

  题目大意:给一个由单词组成的句子,只反转单词内部的次序而不改变单词之间的次序。如“I love you.”转换成“I evol .uoy”。

 1 #include <cstdio>
 2 #include <cstring>
 3 
 4 int main()
 5 {
 6 #ifdef LOCAL
 7     freopen("in", "r", stdin);
 8 #endif
 9     int s, e;
10     char str[100000];
11     while (gets(str))
12     {
13         bool in_word = false;
14         int len = strlen(str);
15         int p = 0;
16         while (p < len)
17         {
18             while (p < len && str[p] == ' ')
19             {
20                 putchar(' ');
21                 p++;
22             }
23             s = p;
24             while (p < len && str[p] != ' ')  p++;
25             e = p - 1;
26             for (int i = e; i >= s; i--)
27                 putchar(str[i]);
28         }
29         printf("\n");
30     }
31     return 0;
32 }
View Code

 

posted @ 2013-09-03 20:40  xiaobaibuhei  阅读(273)  评论(0编辑  收藏  举报