您的位置:首页 > 其它

HDU 1062 字符串翻转 (水题)

2016-01-15 15:57 393 查看
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.


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
char str[1111];
int main()
{
char ch;
int p,i,j;
int t;
cin>>t;
getchar();
while(t--) {
p=0;
while(scanf("%c",&ch)) {
if(ch==' ') {
str[p]='\0';
for(int i=p-1;i>=0;i--) cout<<str[i];
cout<<" ";
p=0;
}
else if(ch=='\n') {
for(int i=p-1;i>=0;i--) cout<<str[i];
cout<<endl;
break;
}
else {
str[p++]=ch;
}
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: