题解 | #迭代器遍历容器#

迭代器遍历容器

https://www.nowcoder.com/practice/0f7ab22e60ee4574a9d9c81412b26595

#include <iostream>
// write your code here......
#include <vector>

using namespace std;

int main() {

    // write your code here......
    int num;
    vector<int> v;

    while (cin >> num) {
        // cin >> num; // 如果把这句放在这里, 而不是 while 后面的括号里, v会多出来一个元素
        v.push_back(num);
    }

    for (auto iterator=v.begin(); iterator!=v.end(); iterator++) {
        cout << *iterator << " ";
    }
    cout << endl;

    for (auto iterator=v.rbegin(); iterator!=v.rend(); iterator++) {
        cout << *iterator << " ";
    }

    cout << endl;

    return 0;
}

全部评论

相关推荐

03-31 14:46
已编辑
门头沟学院 Web前端
励志成为双港第一ja...:这其实很正常,离的太远了,他认为你不会来,就为了混个面试,而且成本很高,实习生都优先选本地高校。吃了地域的亏,所有很多时候地域可能比院校层次更重要。
点赞 评论 收藏
分享
最喜欢秋天的火龙果很...:第一份工作一定要往大的去,工资低点没事。后面换工作会更好找,即使你去小公司,你也不可能不会换工作的。所以找大的去
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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