统计字符数

#include <iostream>
#include <map>
using namespace std;
int main(){
	string n;
	map<char,int> a;
	cin>>n;
	int maxx = 0;
	char m;
	for(int i = 0;i<n.size();i++){
		a[n[i]]++;
	}
	map<char,int> ::iterator i;
	for(i = a.begin();i!=a.end();i++){
		if(i->second>maxx){
			m = i->first;
			maxx = max(maxx,i->second);
		}
	}
	cout<<m<<" "<<maxx;
	return 0;
}

  

posted @ 2024-03-24 09:41  陈若麟  阅读(5)  评论(0编辑  收藏  举报