文章

61

粉丝

81

获赞

17

访问

15.0k

头像
找出众数 题解:c++实现,set去重,count计算出现次数
P2014
发布于2024年3月26日 16:19
阅读数 152

#include<bits/stdc++.h>
using namespace std;

int main (){
    int n, tmp;
    cin >> n;
    set<int> myset;
    int arr[n];

    for(int i = 0; i < n; i++){
        cin >> tmp;
        myset.insert(tmp);
        arr[i] = tmp;
    }

    for(auto it  = myset.begin(); it != myset.end(); ++it){
        if(count(arr, arr+n,*it) > n/2)
            cout << *it;
    }

    return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发