给你一个字符串,包含了空格等标点符号,要你计算出出现次数最多的字母和该字母出现的次数。 /* ============================================================================ Name : mostLetters.c Author : Version : Copyright : Your copyright notice Description : Hello World in C, Ansi-style ============================================================================ */ #include <stdio.h> #include <stdlib.h> #include <assert.h> #define NUM 26*2+6 void getMostLetters(char *str) { assert(NULL != str); int m[NUM] = { 0 }; //存放字母对应的次数,初始化0 char *p; for (p = str; *p != '/0'; p++) { m[*p-65]++; } int i = 0; int count = 0; int ret = 0; for (i = 0; i < NUM; i++) { if (m[i] < count) continue; count = m[i]; ret = i; } printf("%d,%c/n", count, ret+65); } int main(void) { char * str = " aaaaBBBBBBBBBcdeFFFFFFFF "; getMostLetters(str); return EXIT_SUCCESS; }