--- title: "进球" created: 2025-11-28 tags: - 算法 --- # 进球 ## 题目 [进球](https://www.acwing.com/problem/content/description/4719/) ![[image-117d27ba.png]] ## 思路分析 又是典型的计数 unordered\_map 或者换个思路 若某个string出现次数大于n/2 就一定是答案 ## 代码实现 ```cpp #include using namespace std; unordered_map h; int n; int main() { cin>>n; int res=0; string win; while(n--){ string str; cin>>str; h[str]++; if(h[str]>res) { res=h[str]; win=str; } } cout< using namespace std; unordered_map h; int n; int main() { cin>>n; for(int i=0;i>str; h[str]++; if(h[str]*2>n){ cout<