首页 > 其他 > 详细

A1054 The Dominant Color (20分)

时间:2020-01-31 16:45:37      阅读:74      评论:0      收藏:0      [点我收藏+]

一、技术总结

  1. 这个题目也是使用map STL来解决问题。
  2. 直接使用map<int, int>,同时题目规定是严格的Dominate Color,只要有超过一半的数,就可以输出,然后return 0;

二、参考代码

#include<iostream>
#include<map> 
using namespace std;
int main(){
    int m, n;
    scanf("%d %d", &m, &n);
    map<int, int> count;
    int half;
    half = m * n / 2;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            int temp;
            scanf("%d", &temp);
            count[temp]++;
            if(count[temp] > half){
                printf("%d", temp);
                return 0;
            }
        }
    }
    return 0;
}

A1054 The Dominant Color (20分)

原文:https://www.cnblogs.com/tsruixi/p/12245500.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!