反向迭代器
句子逆序
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;
}反向迭代器
查看11道真题和解析
巨人网络成长空间 114人发布