反向迭代器

句子逆序

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

#include <iostream>
#include <map>
#include <unordered_set>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

// 默认输入合法
int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::setvbuf(stdout, nullptr, _IOFBF, BUFSIZ);


    vector<string> sentence;
    string str;
    //默认输入合法
    while (cin>>str) {
        sentence.push_back(move(str));
    }
    const auto end = sentence.crend();
    auto it = sentence.crbegin();
    while (it != end) {
        cout<<*it<<" ";
        it++;
    }

    return 0;
}

反向迭代器

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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