【1054】The Dominant Color (20 分)

简介: 【1054】The Dominant Color (20 分)【1054】The Dominant Color (20 分)
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<algorithm>  
#include<map>
#include<vector>
#include<queue> 
using namespace std;  
int main(){   
   int n,m,col;
   scanf("%d%d",&n,&m); //行与列
   map<int, int> count; //数字与出现次数的map映射
   for(int i=0;i<n;i++){
     for(int j=0;j<m;j++){ //或者写成一个for(m*n)就好了
        scanf("%d",&col); //输入数字
        if(count.find(col)!=count.end())  count [col]++; //若已存在,则次数加1
        else count[col]=1;  //若不存在,则次数置为1
     }
   }
   int k=0,MAX=0;  //最大数字及该数字的出现次数
   for(map<int,int>::iterator it=count.begin();it!=count.end();it++){
     if(it->second>MAX){
       k=it->first; //获取第一关键字(数字),用于输出
       MAX=it->second;  //获取第二关键字(出现次数),用于循环判断
     }
   }
   printf("%d\n",k);
   system("pause");
     return 0;   
}
相关文章
|
9月前
|
JavaScript
background-color设置为透明的方法
background-color设置为透明的方法
148 0
|
前端开发 算法
为什么前端项目里font-weight值不推荐使用数字,而是字重描述符?
为什么前端项目里font-weight值不推荐使用数字,而是字重描述符?
245 0
|
机器学习/深度学习 Windows
Codeforces Round #748 (Div. 3) F - Red-Black Number (记忆化搜索)
Codeforces Round #748 (Div. 3) F - Red-Black Number (记忆化搜索)
93 0
|
前端开发 JavaScript 开发者
L1-032 Left-pad (20 分)
L1-032 Left-pad (20 分)
85 0
|
前端开发
【BUG日记】【CSS】top和bottom、left和right同时存在的时候,left、top优先级最高(无论class、style、!import)
【BUG日记】【CSS】top和bottom、left和right同时存在的时候,left、top优先级最高(无论class、style、!import)
258 0
【BUG日记】【CSS】top和bottom、left和right同时存在的时候,left、top优先级最高(无论class、style、!import)
|
编解码 Android开发
关于Android获取屏幕宽高、dp、sp、px之间的转化
开发过程中,动态创建布局,或者自定义view,少不了需要获取屏幕宽高,这里的宽高指手机屏幕的分辨率,单位是px,而我们在布局文件中用到的空间宽高单位是dp,字体用的是sp。 这几个计量单位之间,是有关联的,比如dp与px,是通过density来相互转化的,px跟sp则通过scaledDensity来相互转化,类似于小学的除数、被除数、商,三者之间的关系。
436 0
|
前端开发 JavaScript 开发者
L1-8 Left-pad (20 分)
根据新浪微博上的消息,有一位开发者不满NPM(Node Package Manager)的做法,收回了自己的开源代码,其中包括一个叫left-pad的模块,就是这个模块把javascript里面的React/Babel干瘫痪了。这是个什么样的模块?就是在字符串前填充一些东西到一定的长度。例如用*去填充字符串GPLT,使之长度为10,调用left-pad的结果就应该是******GPLT。Node社区曾经对left-pad紧急发布了一个替代,被严重吐槽。下面就请你来实现一下这个模块。
100 0