1680: 2018蓝桥杯培训-STL应用专题-day 4 set作业题2

题目描述:
STL库中有许多非常实用的函数,如sort, set, map, vector, queue等。
此题为set集合的应用教学,题目如下:
读入n个数,要求按照从小到大的顺序输出出现的不同数字。
输入:
第一行读入一个 n(0<n <= 1000000)
第二行读入n个整数k ( - 2 ^ 31 <= k <  2 ^ 31 )
输出:
按从小到大的顺序输出不同的数字

样例输入
5
1 3 1 99999999 3

样例输出
1 3 99999999

#include <iostream>
#include <set>
using namespace std;

int main()
{
	set<int> s;
	int n, number;
	set<int>::iterator its;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> number;
		s.insert(number);
	}
	for (its = s.begin(); its != s.end(); its++)
	{
		cout << *its << " ";
	}
	return 0;
}

 

posted on 2022-07-06 23:22  Daniel_lmz  阅读(27)  评论(0)    收藏  举报