解题思路:
使用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 人评分