酷代码 AI
菜单
服务商

C++统计整数出现最高频率次数的实现

```cpp #include <iostream> #include <cstring> #include <algorithm> int main() { int n; std::cin >> n; // 定义一个数组来记录每个数字出现的次数,因为数字范围是 <=100,所以数组大小设为 101 int count[101]; // 使用 memset 函数将数组 count 初始化为 0 memset(count, 0, sizeof(count)); for (int i = 0; i < n; i++) { int num; std::cin >> num; // 对应数字的计数加 1 count[num]++; } int maxCount = 0; for (int i = 0; i <= 100; i++) { // 使用 max 函数找出出现次数最多的数字的出现次数 maxCount = std::max(maxCount, count[i]); } std::cout << maxCount << std::endl; return 0; } ``` ######[AI问答 | 256点数解答 | 2026-05-23 20:09:51]

相关提问
本站限时免费提问中
实用工具查看更多
Linux在线手册 [开发类]
Jquery在线手册 [开发类]
今日油价 [生活类]
图片互转base64 [开发类]
时间转换器 [开发类]