STL编程题1(C++程序设计第8周)

来源:互联网 发布:淘宝搜索页广告位价格 编辑:程序博客网 时间:2024/06/08 01:16

问题描述

下面的程序输出结果是:

1 2 6 7 8 9

请填空:

#include <iostream> #include <iterator> #include <set> using namespace std;int main() {     int a[] = {8,7,8,9,6,2,1}; // 在此处补充你的代码    ostream_iterator<int> o(cout," ");    copy( v.begin(),v.end(),o);     return 0;}

输入

输出

1 2 6 7 8 9

样例输入

样例输出

1 2 6 7 8 9

提示
这道题就一句话,如果不熟练的话其实还是不好想的
源码

#include <iostream>#include <iterator>#include <set>using namespace std;int main(){    int a[] = {8, 7, 8, 9, 6, 2, 1};    //在此处补充你的代码    set<int> v(a, a+7);//关联容器,且不允许相同元素    ostream_iterator<int> o(cout, "");//放到输出流的时候,每放一个整数,就末尾添加一个""中的内容    copy(v.begin(), v.end(), o);//向量V中的数据通过流迭代器o放到o输出流中    return 0;}
0 0