#include <iostream>
#include <assert.h>
using namespace std;
void CalcLowWord_Count(char *str)
{
int max = 0;
int count[26] = {0};
int flag = 0;
int flag2 = 0;
assert(str);
for(int i = 0; str[i] != '\0'; ++i)
{
if(str[i] >= 'a' && str[i] <= 'z')
{
max = (++count[(int)str[i] - 97]) > max ? count[(int)str[i] - 97] : max;
}
}
for(i = 1; i <= max; ++i)
{
for(int j = 0; j < 27; ++j)
{
if(count[j] == i)
{
printf("%c",(char)(j + 97));
flag = 1;
}
}
if( flag )
{
printf(":%d\n",i);
flag = 0;
flag2 = 1;
}
}
if(!flag2)
{
printf("No matched!");
}
}
int main()
{
char *str = "adOaadsfsgAsgBddgmnhkfdghfjfdhfshsfjhfgfpp";
CalcLowWord_Count(str);
return 0;
}
输出字符串各个小写字母对应个数
最新推荐文章于 2022-12-01 08:36:54 发布