1 solutions

  • 0
    @ 2023-1-21 21:02:58
    #include<bits/stdc++.h>
    using namespace std;
    /*
    数组计数统计每个人的得票,再求得票最多的人的编号,也就是统计数组的最大数的下标
    (注意有多个人当选,要求编号最小的,也就是最左侧的最大数下标) 
    */
    int a[210], n, x, ma = 0, m;
    int main()
    {
    	//n人参加竞选,m张投票
    	cin >> n >> m;
    	for(int i = 1; i <= m; i++){
    		cin >> x;
    		a[x]++;//数组计数法 
    	} 
    	for(int i = 1; i <= n; i++){
    		if(a[i] > a[ma]){
    			ma = i;
    		}
    	}
    	cout << ma;
    	return 0;
    }
    
    
    
    • 1

    Information

    ID
    1341
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    10
    Tags
    # Submissions
    5
    Accepted
    1
    Uploaded By