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.
#include <stdio.h>
int main()
{
int t;
scanf("%d",&t);
getchar();
while(t--)
{
char stack[1001];
int top = -1;
char c;
c = getchar();
while(c != '\n')
{
while(c != '\n' && c != ' ')
{
top++;
stack[top] = c;
c = getchar();
}
while(top != -1)
{
putchar(stack[top]);
top--;
}
if(c == ' ')
putchar(c);
if(c != '\n')
c = getchar();
}
putchar('\n');
}
}
PE了很多次,估计是空格的问题,后来改用栈,就AC了