Text Reverse |
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) |
Total Submission(s): 7195 Accepted Submission(s): 1965 |
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. <div style="" font-size:="" 14px;="" border-top:="" #b7cbff="" 1px="" dashed;="" font-family:="" times"=""> |
Author
Ignatius.L
分析:本题涉及到字符串问题,采用边输入边输出的方式,注意用getchar()吃掉换行符。
代码:
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
char a;
char b[100000];
int main()
{
int n,i,p,j;
cin>>n;
getchar();
while(n--)
{
j=0;
while(1)
{
scanf("%c",&a);
if(a=='\n')
break;
if(a!=' ')
b[j++]=a;
else{
b[j]='\0';
if(strlen(b)!=0)
{
printf("%s",strrev(b));
}
j=0;
putchar(a);
}
}
b[j]='\0';
if(strlen(b)!=0)
printf("%s",strrev(b));
cout<<endl;
}
//while(1);
return 0;
}
#include<iostream>
#include<cstring>
using namespace std;
char a;
char b[100000];
int main()
{
int n,i,p,j;
cin>>n;
getchar();
while(n--)
{
j=0;
while(1)
{
scanf("%c",&a);
if(a=='\n')
break;
if(a!=' ')
b[j++]=a;
else{
b[j]='\0';
if(strlen(b)!=0)
{
printf("%s",strrev(b));
}
j=0;
putchar(a);
}
}
b[j]='\0';
if(strlen(b)!=0)
printf("%s",strrev(b));
cout<<endl;
}
//while(1);
return 0;
}