解题思路:
使用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 人评分
简单的a+b (C语言代码)浏览:723 |
【绝对值排序】 (C++代码)浏览:672 |
P1001 (C语言代码)浏览:800 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:609 |
【魔板】 (C++代码)(时间超限,希望会的帮我改正一下)浏览:741 |
用筛法求之N内的素数。 (C语言代码)浏览:646 |
The 3n + 1 problem (C语言代码)浏览:552 |
C二级辅导-统计字符 (C语言代码)浏览:480 |
交换Easy (C语言代码)浏览:761 |
单词个数统计 (C语言代码)浏览:1012 |