题解 | 句子逆序

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

int main() {
    string a;
    getline(cin, a);
    int pos = a.find(' ', 0);
    stack<string> stks;
    while (-1 != pos){
        string b = a.substr(0, pos);
        stks.push(b);
        a.erase(0, pos+1);
        pos = a.find(' ', 0);
    }
    if (a.length() > 0) {
        stks.push(a);
    }
    while (!stks.empty()) {
        cout << stks.top() << " ";
        stks.pop();
    }
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

06-07 17:17
嘉兴学院 教师
心爱的idea:你孩
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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