#include #include #include #include

using namespace std;

int main() { vector votes(10); // 存储学生的投票结果 map<int, int> voteCount; // 存储每个学生的得票数

// 输入学生的投票结果
for (int i = 0; i < 10; i++) {
    cin >> votes[i];
}

// 统计每个学生的得票数
for (int i = 0; i < 10; i++) {
    voteCount[votes[i]]++;
}

// 找到得票数最高的学生编号
int maxVotes = 0;
int maxStudent = 0;
for (auto it = voteCount.begin(); it != voteCount.end(); it++) {
    if (it->second > maxVotes) {
        maxVotes = it->second;
        maxStudent = it->first;
    }
}

// 输出得票数最高的学生编号
cout << maxStudent << endl;

return 0;
c++K博士想在学生中选出一位做自己的助手他一共有10位学生编号分别为1到10。K博士让大家用投票的方式进行选举每位学生只能投给一个人得票最高的学生就将成为K博士的助手。请你编写程序帮K博士找到得票数最高的学生编号。输入 十个整数每个整数表示这位学生投给了对应的编号数字。保证只有一位学生获得最高票数。输出 一个整数表示得票数最高的学生编号。输入样例 1 4 1 4 2 1 3 5 6 2输出样例

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

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