字符反串问题
Problem DescriptionIgnatius 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.
题目意思很简单,看下范例就知道了。。问题就是我不会、我编了个狗P不通的程序。。。很纠结!
本人程序:
#include"stdio.h"
#include"string.h"
int main()
{
int i,a,n,j;
char c[1000],c1[1000],d[2];
scanf("%d",&n);
gets(d);
i=0;
while(i<n)
{
a=0;
gets(c);
for(i=0;c[i]!='\0';i++)
{
if(c[i]==' ')
{
for(j=a;j<=i;j++)
{
c1[j]=c1[i-j];
}
c1[j]=' ';
a=j;
}
}
puts(c1);
}
}