华为机试:句子逆序

#include <iostream>
#include <stack>
#include <string>
using namespace std;

int main() {
    // int a, b;
    // while (cin >> a >> b) { // 注意 while 处理多个 case
    //     cout << a + b << endl;
    // }
    string str;
    stack<string> s;
    while(cin >> str)
    {
        s.push(str);
    }
    while(s.size() > 1)
    {
        cout << s.top() << " ";
        s.pop();
    }
    cout << s.top() << endl;
    s.pop();
}

全部评论
过了没?
点赞 回复 分享
发布于 2023-02-03 23:03 广东

相关推荐

评论
4
1
分享

创作者周榜

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