解题思路:
使用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 人评分
整除问题 (C语言代码)浏览:881 |
printf基础练习2 (C语言代码)浏览:3363 |
【蟠桃记】 (C++代码)(递归计算)浏览:955 |
矩阵乘法 (C++代码)浏览:1456 |
C语言程序设计教程(第三版)课后习题8.1 (C语言代码)浏览:438 |
【亲和数】 (C语言代码)浏览:492 |
输出正反三角形 (C语言代码)格式错误!!!浏览:1140 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:530 |
C语言程序设计教程(第三版)课后习题6.5 (C语言代码)浏览:748 |
C语言程序设计教程(第三版)课后习题6.9 (C语言代码)浏览:762 |