贺州学院ivy


私信TA

用户名:Livy

访问量:21442

签 名:

好好学习,天天向上,汝何秀?

等  级
排  名 130
经  验 7405
参赛次数 5
文章发表 25
年  龄 0
在职情况 学生
学  校 贺州学院
专  业 软件工程

  自我简介:

假猪套天下第一

解题思路:

使用STL中的set集合,set的不重复性和自带排序的功能,完全符合此题的,去除重复和排序的要求

注意事项:

参考代码:

#include<iostream>
#include<math.h>
#include<string>
#include<algorithm>
#include<functional>
#include<set>//需要包含的头文件
using namespace std;
int main(){
 set<int> s;
 int n;
 cin >> n;
 for (int i = 1; i <= n; i++){
  int x;
  cin >> x;
  s.insert(x);
 }
 cout << s.size()<<endl;
 set<int>::iterator it = s.begin();
 for (; it != s.end(); it++){
  cout << *it << " ";
 }
 return 0;
}

 

 

0.0分

4 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答

代码解释器

  评论区