CDZSC_2015寒假新人(1)——基础 g

Description

Ignatius likes to write words in reverse way. Given a single line of text which is written by Ignatius, you should reverse all the words and then output them. 
 

Input

The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow.
Each test case contains a single line with several words. There will be at most 1000 characters in a line. 
 

Output

For each test case, you should output the text which is processed. 
 

Sample Input

3 olleh !dlrow m'I morf .udh I ekil .mca
 

Sample Output

 1 #include<iostream>

 2 #include<cstring>

 3 #include<cstdio>

 4 #include<algorithm>

 5 using namespace std;

 6 int main()

 7 {

 8     char a[1400];

 9     int n;

10     scanf("%d",&n);

11     getchar();

12     while(n--)

13     {

14         gets(a);

15         int len=strlen(a);

16         int next[1500],m=0;

17         for(int i=0;i<=len;i++)

18         {

19             if(a[i]==' '||i==len)

20             {

21                 for(int j=i-1;j>=0&&a[j]!=' ';j--)

22                 {

23                     next[m++]=j;

24                 }

25             }

26             if(a[i]==' ')

27             {

28                 next[m++]=i;

29             }

30         }

31         for(int i=0;i<len;i++)

32         {

33             putchar(a[next[i]]);

34         }

35         printf("\n");

36     }

37 }
View Code

 

hello world! I'm from hdu. I like acm.

Hint

 Remember to use getchar() to read '\n' after the interger T, then you may use gets() to read a line and process it. 

         
 

 

 

你可能感兴趣的:(基础)