句子逆序C++

句子逆序

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

#include<iostream>
#include<stack>
#include<string>
using namespace std;
int main()
{
    string str;
    stack<string> s;
    while(cin>>str)
    {
        s.push(str);
    }
    while(!s.empty())
    {
        cout<<s.top();
        s.pop();
        if(!s.empty())
            cout<<" ";
    }
    return 0;
}
全部评论
我倒是想到栈了,但是我本地自己打的时候不知道怎么退出循环
点赞 回复 分享
发布于 2022-05-25 23:39
妙 我都没想到用栈
点赞 回复 分享
发布于 2021-01-14 17:14
同样本地 visual stdio gcc 测不过。牛客过了?
点赞 回复 分享
发布于 2020-12-01 17:44
为什么本地编译器过不了,牛客过了??
点赞 回复 分享
发布于 2020-03-26 19:04

相关推荐

评论
9
收藏
分享

创作者周榜

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