1,题目描述
Sample Input:
5 3
0 0 255 16777215 24
24 24 0 0 24
24 0 24 24 24
Sample Output:
24
题目大意
就是找这个矩阵中出现次数最多的元素。。。(赤裸裸的送分题)
2,思路
声明map<int,int> data存储每种颜色(数字代表的符号)出现的次数,key为颜色标号,value为出现的次数;
然后遍历每个像素点,并记录。
3,代码
#include<iostream>
#include<map>
using namespace std;
int main(){
//#ifdef ONLINE_JUDGE
//#else
// freopen("1.txt", "r", stdin);
//#endif
map<int,int> data;
int M, N;
cin>>M>>N;
int color;
for(int i = 0; i < M * N; i++){
scanf("%d", &color);
data[color]++;
}
int domColor, maxTimes = 0;
for(auto it : data){
if(it.second > maxTimes){
maxTimes = it.second;
domColor = it.first;
}
}
printf("%d", domColor);
return 0;
}