这是我写的代码,结果完全不正确,求解答,我循环输出b数组的时候数据也不对
1条回答 默认 最新
- 小公鸡卡哇伊呀~ 2021-10-25 20:23关注
下面的代码结果对的:
#include <iostream> using namespace std; int main() { int candidates[6] = {0}; int n = 0; cin >> n; int x; for (int i=1; i <=n; i++) { cin >> x; candidates[x]++; // 投的谁的票, 谁的票数加1 } int max=0; int maxIndex=0; for (int i=1; i <= 5; i++) { if (max <= candidates[i]) { max = candidates[i]; maxIndex = i; } } cout << "winner: " << maxIndex << " with " << max << " votes" << endl; return 0; }
运行结果:
10
1 1 1 1 1 2 2 3 4 5
winner: 1 with 5 votes本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 程序不包含适用于入口点的静态Main方法
- ¥15 素材场景中光线烘焙后灯光失效
- ¥15 请教一下各位,为什么我这个没有实现模拟点击
- ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
- ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
- ¥20 有关区间dp的问题求解
- ¥15 多电路系统共用电源的串扰问题
- ¥15 slam rangenet++配置
- ¥15 有没有研究水声通信方面的帮我改俩matlab代码
- ¥15 ubuntu子系统密码忘记