4.2散列:用map实现重复元素数目的计算
作者:互联网
#include <iostream>
#include<map>
#include<string>
#include<cstdio>
using namespace std;
int main()
{
map<string,int>str;
int n,m;
scanf("%d %d",&n,&m);
string t;
for(int i=0;i<n;++i){
cin>>t;
if(str.count(t)==0){
str[t]=1;
}else{
str[t]+=1;
}
}
for(int i=0;i<n;i++){
cin>>t;
cout<<t<<" "<<str.count(t)<<endl;
}
return 0;
}
4 3
qwe
eee
qwer
asdf
qwe
qwe 1
eee
eee 1
qqqqq
qqqqq 0
标签:map,4.2,int,qwe,qqqqq,str,eee,include,散列 来源: https://www.cnblogs.com/huzhengyu/p/14398174.html