根据国家名字统计人数,然后排序
#include<stdio.h> #include<iostream> #include<queue> #include<map> #include<memory.h> #include <math.h> #include<time.h> #include <stdlib.h> using namespace std; struct Node { string key; int total; }; int main() { freopen("d:\\1.txt","r",stdin); int n; cin>>n; map<string,int>maps; string str; for(int i = 0; i< n;i++) { cin>>str; int j = maps[str]; j++; maps[str] = j; getline(cin,str); } map<string,int>::iterator iter; for(iter = maps.begin(); iter != maps.end(); ++iter) { cout<<iter->first<<" "<<iter->second<<endl; } return 0; }
时间: 2024-11-11 03:58:33