您的位置:首页 > 其它

HDU 1062 Text Reverse(字符串)

2016-02-24 14:04 429 查看

Text Reverse

[align=left]Problem Description[/align]
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.

[align=left]Input[/align]
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.

[align=left]Output[/align]
For each test case, you should output the text which is processed.

[align=left]Sample Input[/align]

3
olleh !dlrow

m'I morf .udh

I ekil .mca

[align=left]Sample Output[/align]

hello world!

I'm from hdu.

I like acm.

Hint

Remember to use getchar() to read '\n' after the interger T, then you may use gets() to read a line and process it.

[align=left]Wrong Answer[/align]
用sstream去做,感觉挺对的啊,却一直PE。
另外HDU最近有点抽啊。

#include <cstdio>
#include <iostream>
#include <sstream>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#define PI acos(-1.0)
#define ms(a) memset(a,0,sizeof(a))
#define msp memset(mp,0,sizeof(mp))
#define msv memset(vis,0,sizeof(vis))
#define msd memset(dp,0,sizeof(dp))
using namespace std;
//#define LOCAL
int main()
{
#ifdef LOCAL
freopen("in.txt", "r", stdin);
//freopen("out.txt","w",stdout);
#endif // LOCAL
//ios::sync_with_stdio(false);
int N;
cin>>N;
getchar();
while(N--)
{
char a[1001];
char b[1001];
gets(a);
for(int i=0,as=strlen(a),cur=0;i<as;i++)
{
b[cur++]=a[i];
if(a[i]==' ')
{
for(int j=cur-2;j>=0;j--)
printf("%c",b[j]);
printf(" ");
cur=0;
}
if(i==as-1)
{
for(int j=cur-1;j>=0;j--)
printf("%c",b[j]);
printf("\n");
}
}
}
return 0;
}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: