top1编程
← 返回题目
题解

【入门】宇宙总统

2 条题解

  • 0
    @ 2026-7-29 0:06:22
    #include<bits/stdc++.h>
    using namespace std;
    int main(){
    	int n,t[105]={},x,ma=0,b;
    	cin>>n;
    	for(int i=1;i<=n;i++){
    		cin>>x;
    		t[x]++;
    	}
    	for(int i=1;i<=100;i++){
    		if(t[i]>=ma){
    			ma=t[i];
    			b=i;
    		}
    	}
    	cout<<b;
    	return 0;
    }
    
    • 0
      @ 2026-7-28 22:44:44
      #include<bits/stdc++.h>
      using namespace std;
      struct zt{
      	int bh,ps;
      }a[1010];
      bool cmp(zt a,zt b){
      	if(a.ps>b.ps||a.ps==b.ps&&a.bh>b.bh){
      		return true;
      	}
      	else{
      		return false;
      	}
      }
      int main(){
      	int n,x;
      	cin>>n;
      	for(int i=0;i<n;i++){
      		cin>>a[i].bh;
      		a[a[i].bh].ps++;
      	}
      	sort(a,a+n,cmp);
      	cout<<a[0].bh;
      	
      }
      
      • 1