c语言字符串字数统计,统计字符数 (C++代码)

解题思路:

注意事项:

参考代码:

#include

#include

using namespace std;

int main()

{

int n,m;

cin>>n;

while(n--)

{

char a[1000];

int b[26]={0};

scanf("%s",a);

for(int i=0;a[i]!='\0';i++)

{

if(a[i]=='a') b[0]++;

else if(a[i]=='b') b[1]++;

else if(a[i]=='c') b[2]++;

else if(a[i]=='d') b[3]++;

else if(a[i]=='e') b[4]++;

else if(a[i]=='f') b[5]++;

else if(a[i]=='g') b[6]++;

else if(a[i]=='h') b[7]++;

else if(a[i]=='i') b[8]++;

else if(a[i]=='j') b[9]++;

else if(a[i]=='k') b[10]++;

else if(a[i]=='l') b[11]++;

else if(a[i]=='m') b[12]++;

else if(a[i]=='n') b[13]++;

else if(a[i]=='o') b[14]++;

else if(a[i]=='p') b[15]++;

else if(a[i]=='q') b[16]++;

else if(a[i]=='r') b[17]++;

else if(a[i]=='s') b[18]++;

else if(a[i]=='t') b[19]++;

else if(a[i]=='u') b[20]++;

else if(a[i]=='v') b[21]++;

else if(a[i]=='w') b[22]++;

else if(a[i]=='x') b[23]++;

else if(a[i]=='y') b[24]++;

else if(a[i]=='z') b[25]++;

}

int max=b[0],q;

int c[26],g=0;

for(int i=0;i<26;i++)

if(max

max=b[i];

for(int i=0;i<26;i++)

if(max==b[i])

{

c[g++]=i;

}

char d[50];

for(int i=0;i

{

d[i]='a'+c[i];

}

cout<

}

return 0;

}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值