首页 > 其他 > 详细

zju pat 1054 The Dominant Color

时间:2014-01-30 02:19:56      阅读:389      评论:0      收藏:0      [点我收藏+]
bubuko.com,布布扣
//1052 有些节点并不属于链表,因此单纯排序,会有一个case过不去
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
int main()
{
    int n,m,i;
    map<int,int> map_s;
    int color;
    int dom_color;
    int max_num;
    while(cin>>n>>m)
    {
        for(i = 0 ;i < n*m;i++)
        {
            scanf("%d",&color);
            map_s[color]++;
        }
        map<int,int>::iterator it = map_s.begin();
        max_num = -1;
        for(;it!=map_s.end();it++)
        {
            if(it->second > max_num)
            {
                max_num = it->second;
                dom_color = it->first;
            }
        }
        cout<<dom_color<<endl;
        map_s.clear();
    }
    return 0;
}
bubuko.com,布布扣

zju pat 1054 The Dominant Color

原文:http://www.cnblogs.com/cheng07045406/p/3536385.html

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