跳到正文

题解

题解:CF1674G Remove Directed Edges

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

文章信息

发布
2025年7月22日
收录
2025年12月12日
更新
2026年11月3日
篇幅
约 1 分钟
题目
CF1674G

版本

  1. v1当前

P15154 [SWERC 2024] The king of SWERC 题解

题目大意

输入 nn 个字符串,求出出现次数最多的字符串。

思路

用哈希可以很快解决,但是显然用 mapmap 会更简洁,直接开一个 mapmap 村字符串出现的次数,打擂台找最大就行了。

code

C++
#include<bits/stdc++.h>
using namespace std;
int n,maxn;
map<string,int> mp;
string ans;
int main(){
	cin >> n;
	for(int i = 1;i <= n;i++){
		string s;
		cin >> s;
		mp[s]++;
		if(mp[s] > maxn){
			ans = s;
			maxn = mp[s];
		}
	}
	cout << ans;
	return 0;
}
原文