1042 字符统计

时间:2020-02-19 18:54:51   收藏:0   阅读:53

水题,又是一道hash题。

#include<iostream>
#include<cctype>
using namespace std;

int hashtable[26]= {0};
int main() {
    char c;
    while(scanf("%c",&c)!=EOF) {
        if(isalpha(c)) {//是字母?
            if(isupper(c))//大写字母转小写字母
                c+=32;
            hashtable[c-a]++;
        }
    }
    int max = 0,pos = -1;
    for(int i = 0; i < 26; ++i)
        if(max < hashtable[i]) {
            max  = hashtable[i];
            pos = i;
        }
    printf("%c %d",pos+a,max);
    return 0;
}

技术分享图片

 

原文:https://www.cnblogs.com/keep23456/p/12332373.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!