#include <iostream>
#include<cstring>
#include "string"
#include <iomanip>
#include<math.h>
#include<algorithm>
#include<map>
using namespace std;
//typedef struct{
// string r;
// int count=0;
//}p;
map<string,int>m;
int main() {
string s;
// p k[10000];
int a[10000];
int index=0;
while(cin>>s)
{
m[s]++;
// int flag=0;
// for(int i=0;i<index;i++)
// {
// if(k[i].r==s)
// {
// k[i].count++;
// flag=1;
// break;
// }
// }
// if(flag==0)
// {
// k[index].r=s;
// k[index].count=1;
// index++;
// }
}
map<string,int>::iterator it;
for(it=m.begin();it!=m.end();it++)
{
cout<<it->first<<":"<<it->second<<"\n";
}
return 0;
}
统计每个单词数量(结构体/map迭代器)(自用)
最新推荐文章于 2024-07-22 23:59:01 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)