0
点赞
收藏
分享

微信扫一扫

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

追风骚年 2022-02-05 阅读 45
#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;
 } 
举报

相关推荐

0 条评论