#include <iostream> #include <set> using namespace std; int main() { int n; cin>>n; set<int> s; while(n--) { int x; cin>>x; s.insert(x); } for(auto it:s) cout<<it<<"\n"; return 0; } // 64 位输出请用 printf("%lld")
set能完美契合题目要求,即统计与排序的功能,最后范围遍历set容器输出即可
#include <iostream> #include <set> using namespace std; int main() { int n; cin>>n; set<int> s; while(n--) { int x; cin>>x; s.insert(x); } for(auto it:s) cout<<it<<"\n"; return 0; } // 64 位输出请用 printf("%lld")
set能完美契合题目要求,即统计与排序的功能,最后范围遍历set容器输出即可