题目难度:一颗星
题目大意:给出一串数字,找出其中的众数。
题目坑点:还是cin的问题,继续弄scanf就好了啊,这是彻底要逼我用c不用c艹。尽量改改习惯咯。
代码如下:
#include<iostream>
#include<stdlib.h>
#include<queue>
#include<stack>
#include<algorithm>
#include<map>
#include<cstring>
using namespace std;
int main(){
int M,N;
cin>>M>>N;
int temp;
map<int,int> resolution;
for(int i=0;i<N;i++){
for(int j=0;j<M;j++){
scanf("%d",&temp);//继续注意scanf
if(resolution.find(temp)!=resolution.end()){
resolution[temp]++;
}
else{
resolution[temp]=1;
}
}
}
int maxsize=0,maxcolor=-1;
for(map<int,int>::iterator it=resolution.begin();it!=resolution.end();it++){
if(it->second>maxsize){
maxsize=it->second;
maxcolor=it->first;
}
}
cout<<maxcolor;
}