STL容器——set实现自动排序(无重复元素)

#include<iostream>
#include<set>
#include<algorithm>
//automatic sorting with set
// no duplicated elements
using namespace std;

int main()
{
	set<int> s;
	int n, x;
	scanf("%d", &n);  // how many numbers that you want to input
	for(int i = 0; i < n; i ++)
	{
		scanf("%d", &x);
		s.insert(x); //insert into set
	}
	set<int> :: iterator it;  //define a iterator
	for(it = s.begin(); it != s.end(); it ++)
	cout<< *it <<" ";  //output
	return 0;
 } 

上一篇:【PTA】【C语言】找二维数组中最大数及所在行列号


下一篇:Codeforces Round #752 (Div. 2)补题题解