解题思路:
使用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 人评分
2003年秋浙江省计算机等级考试二级C 编程题(1) (C语言代码)浏览:542 |
C语言程序设计教程(第三版)课后习题7.2 (C语言代码)浏览:1051 |
C语言程序设计教程(第三版)课后习题8.9 (C语言代码)浏览:560 |
钟神赛车 (C++代码)浏览:863 |
2004年秋浙江省计算机等级考试二级C 编程题(1) (C语言代码)浏览:458 |
C语言训练-列出最简真分数序列* (C语言代码)浏览:500 |
C语言训练-大、小写问题 (C语言代码)浏览:611 |
【金明的预算方案】 (C++代码)浏览:837 |
a+b浏览:432 |
C语言程序设计教程(第三版)课后习题4.9 (C语言代码)浏览:560 |