B1042 字符统计 (20 分)

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int hashTable[26];
int main(){
	string str;
	getline(cin, str);
	int len = str.length();
	for(int i = 0; i < len; i++){
		if(str[i] >= 'a' && str[i] <= 'z'){
			int a = str[i] - 'a';
			hashTable[a]++;
		}
		if(str[i] >= 'A' && str[i] <= 'Z'){
			int a = str[i] - 'A';
			hashTable[a]++;
		}
	}
	int num = 0;
	int index = 0;
	for(int i = 0; i < 26; i++){
		if(hashTable[i] > num){
			index = i;
			num = hashTable[i];
		}
	}
	printf("%c %d", 'a'+index, num);
}
posted @ 2019-11-07 09:42  睿晞  阅读(110)  评论(0编辑  收藏  举报