解题思路:
使用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 人评分
printf基础练习2 (C语言代码)浏览:316 |
C语言训练-大、小写问题 (C语言代码)浏览:783 |
WU-蓝桥杯算法提高VIP-勾股数 (C++代码)浏览:1669 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:585 |
C语言程序设计教程(第三版)课后习题5.8 (C语言代码)浏览:681 |
The 3n + 1 problem (C语言代码)浏览:596 |
第三届阿里中间件性能挑战赛-总决赛亚军比赛攻略浏览:1166 |
C语言程序设计教程(第三版)课后习题1.6 (C语言代码)浏览:690 |
C语言程序设计教程(第三版)课后习题11.3 (C语言代码)浏览:652 |
回文数(一) (C语言代码)浏览:1165 |