Text Reverse

1909 ワード

Text Reverse
Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 20   Accepted Submission(s) : 12
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem 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
hello world!
I'm from hdu.
I like acm.

タグスペースの個数は、スペースに遭遇するたびに前のスペースに逆出力され、もう1つのスペースが出力されます.最後のスペース出力が終わったら、残りのすべての文字を直接出力!!!
#include
#include
#include
char str[1500];
int main()
{
int len,i,n,j,k,a,t;
scanf("%d",&n);
getchar();
while(n--)
{
gets(str);
len=strlen(str);
a=0;
for(i=0;i{
if(str[i]==' ')
a++;
}
while(a)
{
k=0;
for(i=0;i   {
   if(str[i]==' ')
   {
  for(j=i-1;j>=k;j--)
 printf("%c",str[j]);
  printf("%c",str[i]);//文字を出力するたびにスペースが出力されます 
  a--;
  k=i+1;
   }
   }
}
for(t=len-1;t>=k;t-)/注意ここでlen番目のビットから直接出力すると、スペースが出力されます 
printf("%c",str[t]);
   printf("");
}
//system("pause");
return 0;
}