题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1062
C语言源码:
#include<stdio.h>
#include<string.h>
int main()
{
int n,i,flag,j;
char s[1001];
while(scanf("%d",&n)!=EOF)
{
getchar();//scanf会把回车一起输到缓冲区,gets不会!
while(n--)
{
gets(s);
flag=0;
for(i=0;i<(int)strlen(s);i++)
{
if(s[i]==' ')
{
for(j=i-1;j>=flag;j--)
printf("%c",s[j]);
printf(" ");
flag=i+1;
}
}
for(j=i-1;j>=flag;j--)
printf("%c",s[j]);
printf("\n");
}
}
}