首页 > 其他 > 详细

HUST 1339 Reversal

时间:2016-01-26 16:29:47      阅读:135      评论:0      收藏:0      [点我收藏+]
  Memory Limit: 131072KB   64bit IO Format: %lld & %llu

Description

You will get line with some words(only lowercase and uppercase, no other characters), input it and make all the word reversal and output.

Input

The first line is a number T means there are T cases. For each case: The first line is N means next line has N words. All the words in a line and between two words only one blank. (No more than 100 words, and each word length not exceeded 10)

Output

For each case, output a line with the reversal word in the input order. Between two words has exact one blank, but DO NOT output an blank at the end of a line.

Sample Input

3
4
I am a man
4
I will AC it
3
I love ACM

Sample Output

I ma a nam
I lliw CA ti
I evol MCA

http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=14218
题解:将每个单词倒置,可以用char数组,然后用空格分隔,这里用的是string和stringstream。
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <cstring>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#include <map>
using namespace std;
//#define LOCAL

int main()
{
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
#endif // LOCAL
    //Start
    int N;
    cin>>N;
    while(N--)
    {
        int t;
        cin>>t;
        getchar();
        string s,sss;
        getline(cin,s);
        stringstream ss(s);
        int i=0;
        while(ss>>sss)
        {
            string::iterator it=sss.end()-1;
            if(i++!=0)printf(" ");
            while(it!=sss.begin())
            {
                cout<<*it;
                it--;
            }
            cout<<*it;
        }
        printf("\n");
    }
    return 0;
}

 

HUST 1339 Reversal

原文:http://www.cnblogs.com/gpsx/p/5160685.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!