题解 | #句子逆序#

句子逆序

https://www.nowcoder.com/practice/48b3cb4e3c694d9da5526e6255bb73c3

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

int main() {
    string str;
    string newstr;
    string word;
    char c;
    while(getline(cin,str)){
        while(!str.empty()){
            c = str.back();
            if(c!=' '){
                word.insert(0,1,c);
            }
            else{
                word.push_back(' ');
                newstr += word;
                word.clear();
            }
            str.pop_back();
        }
        newstr.insert(newstr.size(),word);
        cout << newstr << endl;
        newstr.clear();
    }
    return 0;
}

全部评论

相关推荐

03-26 12:00
已编辑
门头沟学院 Java
offer魅魔_oc...:100-200每天,你还要倒贴100
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务