Blucoris 2021-11-16 18:26 采纳率: 75%
浏览 96
已结题

为什么老是提示未知重写说明符,这是怎么回事呢?


/*编一函数,功能为统计字符串中各个字母(不区分大、小写)出现的频率,同时找出频率出现最高的字母及次数,假设出现次数最多的字母只有一个。函数形式为:‌
void freq(char s[],int p[],char &chmax,int &max)‌:*/
#include<iostream>
#include<string.h>
using namespace std;
int freq(char s[],int p[],char &chmax,int &max)‌
    {char *q=s;
      int i,j;
      while(*q)
{if(*q<='z'&&*q>='a'||*q<='Z'&&*q>='A')
    {if(*q>='a')
        p[*q]++;
    else
        p[*q+32]++;
    if(p[*q]>max)
        {max=p[*q];
    chmax=*q;}
      q++;}
}
return 0;
}
int main()
{char ch[100]="";char chmax;int max;int i;
int sum[100]={0};
gets_s(ch);
freq(ch,sum,chmax,max);
for(i=1;ch[i]!='\0';i++)
    if(sum[i])
        cout<<ch[i]<<"----"<<sum[i]<<endl;
cout<<"出现频率最高的数为:"<<endl;
cout<<chmax<<"----"<<max<<endl;
system("pause");
return 0;
}

为什么跑不了,这是什么回事呢?谢谢

  • 写回答

1条回答 默认 最新

  • 从善若水 5G/6G通信领域优质创作者 2021-11-16 18:45
    关注
    
    int main()
    {
        char ch[100]="";char chmax;int max;int i;
        int sum[256]={0};
        gets(ch);
        freq(ch,sum,chmax,max);
        for(i=1;ch[i]!='\0';i++)
            if(sum[ch[i]])
                cout<<ch[i]<<"----"<<sum[ch[i]]<<endl;
        cout<<"出现频率最高的数为:"<<endl;
        cout<<chmax<<"----"<<max<<endl;
        system("pause");
        return 0;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 12月18日
  • 已采纳回答 12月10日
  • 创建了问题 11月16日

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度