跳到正文

题解

题解:P15154 [SWERC 2024] The king of SWERC

ycy25约 1 分钟
原文
文章信息与版本

文章信息

发布
2026年2月3日
收录
2026年6月14日
更新
2026年11月15日
篇幅
约 1 分钟
获赞
2
题目
P15154

版本

  1. v1当前

思路

用一个 map 存储每位候选人有多少张选票,最后用擂台法求出得票最多的人是谁即可。

代码

C++
#include<bits/stdc++.h>
using namespace std;
map<string,int>p;
int main()
{
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int n;
    cin>>n;
    string s;
    for(int i=1;i<=n;i++)
    {
        cin>>s;
        p[s]++;
    }
    int maxn=0;
    for(auto it=p.begin();it!=p.end();it++)
    {
        if(it->second>maxn)
        {
            maxn=it->second;
            s=it->first;
        }
    }
    cout<<s;
    return 0;
}
原文