c++(stringstream字符串分割空格)

1205 单词翻转

 

时间限制: 1 s
空间限制: 128000 KB
题目等级 : 青铜 Bronze
 
 
 
题目描述 Description

给出一个英语句子,希望你把句子里的单词顺序都翻转过来

输入描述 Input Description

输入包括一个英语句子。

输出描述 Output Description

按单词的顺序把单词倒序输出

样例输入 Sample Input

I love you

样例输出 Sample Output

you love I

数据范围及提示 Data Size & Hint

简单的字符串操作

#include <iostream>
#include <iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include <stdio.h>
#include <string.h>
#include <queue>
#include<sstream>
using namespace std;


int main()
{
    string a ;
    vector<string>res;
    getline(cin , a);
    stringstream ss(a);
    string b ;
    while(ss >> b)
    {
        res.push_back(b);
    }
    for(int i = res.size() - 1 ; i > 0 ; i --)
        cout << res[i] << " " ;
    cout << res[0] << endl ;



    return 0 ;
}

猜你喜欢

转载自www.cnblogs.com/nonames/p/11256444.html