• 九度oj 题目1057:众数


    题目1057:众数

    时间限制:1 秒

    内存限制:32 兆

    特殊判题:

    提交:9744

    解决:3263

    题目描述:

    输入20个数,每个数都在1-10之间,求1-10中的众数(众数就是出现次数最多的数,如果存在一样多次数的众数,则输出权值较小的那一个)。

    输入:

    测试数据有多组,每组输入20个1-10之间的数。

    输出:

    对于每组输入,请输出1-10中的众数。

    样例输入:
    5 1 5 10 3 5 3 4 8 6 8 3 6 5 10 7 10 2 6 2 
    样例输出:
    5
     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 using namespace std;
     5 
     6 int main(){
     7     int a[11], temp, max, cnt;
     8     while(cin >> temp){
     9         memset(a, 0, sizeof(a));
    10         a[temp]++;
    11         for(int i = 0; i < 19; i++){
    12             cin >> temp;
    13             a[temp]++;
    14         }
    15         max = 10, cnt = a[10];
    16         for(int i = 9; i >= 0; i--){
    17             if(a[i] >= cnt){
    18                 max = i;
    19                 cnt = a[i];
    20             }
    21         }
    22         cout << max << endl;
    23     }
    24     return 0;
    25 }
     
  • 相关阅读:
    oc复习
    oc复习(琐碎)
    nodejs中express框架
    mac 下subline text 3最新版本激活码
    mac eclipse 修改SDK路径
    MAC下 ant 环境搭建
    nodejs npm命令行总结
    ios开发之短信验证
    ios开发之调用相机和本地相册
    ios8新特性之毛玻璃效果
  • 原文地址:https://www.cnblogs.com/qinduanyinghua/p/6482993.html
Copyright © 2020-2023  润新知