题解 | #句子逆序#

句子逆序

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

#include<iostream>
#include<stack>
using namespace std;
int main() {
    string text;
    getline(cin, text);
    stack<string> sta;
    string str;
    for(int i=0;i<text.length();i++) {
        if(text[i] != ' ') {
            str += text[i];
        }else {
            sta.push(str);
            str = "";
        }
        if(i == text.length()-1) {
            sta.push(str);
        }
    }
    while(!sta.empty()) {
        if(sta.size()==1)
            cout<<sta.top();
        else
            cout<<sta.top()<<" ";
        sta.pop();
    }
    cout<<endl;
    return 0;
}
全部评论

相关推荐

投递拓竹科技等公司10个岗位
点赞 评论 收藏
分享
点赞 评论 收藏
分享
07-07 12:25
门头沟学院 Java
程序员牛肉:你这个智邮公司做的就是那个乐山市税务系统的服务吗?
点赞 评论 收藏
分享
评论
2
收藏
分享

创作者周榜

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