#include <iostream>
#include <vector>
#include <unordered_map>

using namespace std;

int main() {
    int n;
    cin >> n;
    
    unordered_map<int, int> count; // 用于统计每个选手的票数
    
    for (int i = 0; i < n; i++) {
        int id;
        cin >> id;
        count[id]++; // 统计选手的票数
    }
    
    int maxCount = 0; // 最多的票数
    for (auto& p : count) {
        if (p.second > maxCount) {
            maxCount = p.second;
        }
    }
    
    cout << maxCount << endl;
    
    return 0;
}
``
题目描述班上要进行一场班长竞选共有10名同学参加。每个同学都有一个唯一的编号id编号是1~10之间的整数。现在收集上来n张选票每张选票上都只有一个候选人的编号id。请你统计每个选手票数输出获得最多选票的票数。输入第一行一个正整数n。1 = n = 1000第二行n个空格隔开的正整数表示选票上的候选人编号id。输出一行表示获得最多选票的票数。样例输入 复制101 2 3 2 4 5 9 10 1 1

原文地址: https://www.cveoy.top/t/topic/ic77 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录