字符统计2

来源:互联网 发布:mac qq远程 外置 编辑:程序博客网 时间:2024/06/02 07:11


字符统计2

Time Limit: 1000MS Memory limit: 65536K

题目描述

输入英文句子,输出该句子中除了空格外出现次数最多的字符及其出现的次数。

输入

输入数据包含多个测试实例,每个测试实例是一个长度不超过100的英文句子,占一行。

输出

逐行输出每个句子中出现次数最多的字符及其出现的次数(如果有多个字符的次数相同,只输出ASCII码最小的字符)。

示例输入

I am a studenta good programming problemABCD abcd ABCD abcd

示例输出

a 2o 4A 2

提示

 

来源

/*************************************************************************> File Name: 字符统计2.c> Author: ttop5> Blog: www.ttop5.net> Mail: 1427154738@qq.com> Created Time: 2014年12月13日 星期六 21时44分18秒 ************************************************************************/#include<stdio.h>#include<memory.h>#include<string.h>int main(){    int cont[125];    char str[100];    int i,mark,max;    while(gets(str)!=NULL)    {        memset(cont,0,sizeof(int)*125);        for(i=0; i<strlen(str); i++)        {            if(str[i]!=' ')                cont[str[i]]++;        }        max=0;        for(i=65; i<123; i++)        {            if(max<cont[i])            {                max=cont[i];                mark=i;            }        }        printf("%c %d\n",mark,max);    }    return 0;}


0 0
原创粉丝点击