006:编程填空:去除重复元素排序

描述

程序填空,使其按要求输出

#include <iterator>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <stack>
#include <iostream>
#include <set>
using namespace std;

int main() {
	int t;
	int  a[100];
	cin >> t;
	while(t--) {
		for(int i = 0;i < 12; ++i)
			cin >> a[i];
// 在此处补充你的代码
std::copy(b.begin(), b.end(), c);
		cout << endl;

	}
	return 0;
}

输入

第一行是个整数,表示输入数据组数 
每组数据一行,有12个整数

输出

对每组数据, 将12个整数从小到大排序并去除重复元素后输出

样例输入

2
34 5 4 6 3 9 8 34 5 3 3 18
31 2 4 6 2 9 8 31 5 3 3 18

样例输出

3 4 5 6 8 9 18 34 
2 3 4 5 6 8 9 18 31 

提示

注意:行末都有一个空格


#include <iterator>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <stack>
#include <iostream>
#include <set>
using namespace std;

int main()
{
    int t;
    int a[100];
    cin >> t;
    while (t--)
    {
        for (int i = 0; i < 12; ++i)
            cin >> a[i];

        // 在此处补充你的代码
        ostream_iterator<int> c(cout, " ");
        sort(a, a + 12);
        vector<int> b;
        for (int i = 0; i < 12; i++)
        {
            if (a[i] != a[i + 1])
                b.push_back(a[i]);
        }

        std::copy(b.begin(), b.end(), c);
        cout << endl;
    }
    return 0;
}

ostream_iterator是流迭代器。
流迭代器是标准模板库中的。因此是类模板。
ostream_iterator<int>
指定了类型,就是迭代器读写的类型。
通过这个流迭代器可以把你要输入的写入到指定的流中。
cout就是指定的流。就是标准输出。
可以改成一个输出流就可以,比如一个文件。
通俗的一点说,你把它看成一个指向输出流的指针。通过这个指针你可以把东西写到输出流中。
copy (v.begin(),v.end(),output);
这个意思就是说,把向量V中的数据放到cout输出流中,通过流迭代器output.
ostream_iterator<int> output(cout ,"*");
这个的意思说,放到输出流的时候,每放一个整数,就末尾添加一个*. 

来源:http://zhidao.baidu.com/question/157221479.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值