统计字符串中出现最多次数的字母

来源:互联网 发布:交换机修改telnet端口 编辑:程序博客网 时间:2024/05/01 08:07
#include <stdio.h>#include <string.h>#define MAX 80    /*定义字符串最大长度*/char  maxnum(char str[]);void main(){  char str[MAX];  printf("Please Input A String:");  gets(str);  printf("%s%c\n","The letter Coming Up Frequently Is:",maxnum(str));}char  maxnum(char str[]){    int  i=0,num[27]={0},max;    char ch;    while (ch=str[i++])    {       num[ch-'a'+1]++;    }    max=num[1];    for (i=2;i<=26;i++)      if (num>max)      {max=num;        ch=i+'a'-1;      }    return(ch);}


原创粉丝点击