抵消方法
#include<iostream>
using namespace std;
int main(){
int n , m;
int count=0,temp;
cin>>n>>m;
cin>>temp;//第一个
count=1;
for(int i=1;i<n*m;i++){
int ans;
//cin>>ans;//一个2分的测试点会超时
scanf("%d",&ans);
if(temp==ans){
count++;
}
else{
if(count>0){
count--;
}
else{
count=1;
temp=ans;
}
}
}
cout<<temp<<endl;
return 0;
}
map
#include<iostream>
#include<map>
using namespace std;
int main(){
int n,m;
cin>>n>>m;
map<int,int> count;
for(int i=0;i<n*m;i++){
int ans;
scanf("%d",&ans);
if(count.find(ans)!=count.end()){
count[ans]++;
}
else{
count[ans]=1;
}
}
int maxnum=0,maxcount=0;
for(map<int,int>::iterator it=count.begin();it!=count.end();it++){
if(it->second>maxcount){//count[it->first]==it->second;
maxcount=it->second;
maxnum=it->first;
}
}
cout<<maxnum<<endl;
}