计蒜客习题5:蒜头君的藏书(map)(STL)

 

#include<bits/stdc++.h>
using namespace std;
int n;
char name[105];
map<string,int> mp;
int main()
{
	scanf("%d",&n);//因为n<10^6 用cin cout会超时
	for(int i=0;i<n;++i){
		
		scanf("%s",name);//慎用c_str
		mp[name]++;
	} 
	printf("%d\n",mp.size());
	for(map<string,int>::iterator it=mp.begin();it!=mp.end();++it){
		printf("%s %d\n",(it->first).c_str(),it->second);
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/intmain_S/article/details/89499280