扩大
缩小

TOJ1153. Word Reversal

1153.   Word Reversal
Time Limit: 1.0 Seconds   Memory Limit: 65536K
Total Runs: 5327   Accepted Runs: 2132    Multiple test files



For each list of words, output a line with each word reversed without changing the order of the words.


Input

You will be given a number of test cases. The first line contains a positive integer indicating the number of cases to follow. Each case is given on a line containing a list of words separated by one space, and each word contains only uppercase and lowercase letters.


Output

For each test case, print the output on one line.


Sample Input

3
I am happy today
To be or not to be
I want to win the practice contest


Sample Output

I ma yppah yadot
oT eb ro ton ot eb
I tnaw ot niw eht ecitcarp tsetnoc
View Code
 1 #include<iostream>
 2 #include<stack>
 3 using namespace std;
 4 #include<string.h>
 5 #include<stdio.h>
 6 stack<char> s;
 7 char str[1000];
 8 int main()
 9 {
10     int n,i,len;
11     cin>>n;
12     getchar();
13     while(n--)
14     {
15        //cin>>str;
16       gets(str);
17        len=strlen(str);
18        i=0;
19        while(1)
20        {
21           while(str[i]!=' '&&i<len)
22           {
23               s.push(str[i]);
24               i++;
25           }
26           while(!s.empty())
27           {
28              cout<<s.top();
29              s.pop();
30           }
31           if(i!=len)
32           {
33               cout<<' ';
34               i++;
35           }
36           else break;
37         
38        }
39        cout<<endl;
40           
41   
42     }
43     return 0;
44 }
45           
46           

 

posted on 2012-08-02 14:58  LinuxPanda  阅读(423)  评论(0编辑  收藏  举报

导航