#34450: c++ map


k0905920491@gmail.com (魚( ´•̥ו̥` ))

學校 : 國立新竹高級工業職業學校
編號 : 136251
來源 : [120.126.77.9]
最後登入時間 :
2025-05-17 17:20:41

利用c++內建STL的map

自動存入key與value,最後還會以key排序!

include <iostream>
#include <map>
using namespace std;
int main(){
    int n,tem;
    map<int,int> ans;
    cin>>n;
    while(n--){
        cin>>tem;
        tem = (tem%1000)/10;
        ans[tem]++;
    }
    for(map<int,int>::iterator it=ans.begin();it!=ans.end();it++){
        cout<<it->first<<" "<<it->second<<endl;
    }
}