码迷,mamicode.com
首页 > 其他好文 > 详细

A1054 The Dominant Color (20分)

时间:2020-01-31 16:00:30      阅读:68      评论:0      收藏:0      [点我收藏+]

标签:++   技术总结   scanf   mina   name   return   include   pre   直接   

一、技术总结

  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分)

标签:++   技术总结   scanf   mina   name   return   include   pre   直接   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!