使用哈希表统计每个数出现的次数
#include<bits/stdc++.h> using namespace std; int main() { int n; cin>>n; map<int,int> h; for(int i=1;i<=n;i++) { int x; cin>>x; h[x]++; //x出现的次数增加 } for(auto it:h) //遍历整个哈希表 { cout<<it.first<<" "<<it.second<<endl; } return 0; }
Using your lizikid universal account