NYOJ--95--multiset--众数问题

/*
    Name: NYOJ--95--众数问题
    Date: 20/04/17 16:02
    Description: multiset水过 
*/
#include<set>
#include<iostream> 
using namespace std;
multiset<int> st;
int main(){
    ios::sync_with_stdio(false);
    int n;cin>>n;
    while(n--){
        st.clear();
        int m;cin>>m;
        for(int i=0; i<m; ++i){
            int a;cin>>a;
            st.insert(a);
        }
        int max_val,ct,k;
        max_val = 0;ct = 0;
        for(multiset<int>::iterator it=st.begin(); it!=st.end(); ++it){
            if((*it) >= max_val){
                if((k = st.count((*it))) > ct) {
                    max_val = (*it);
                    ct = k;
                }
            }
        }
        cout<<max_val<<" "<<ct<<endl;
    }
    return 0;
}
原文地址:https://www.cnblogs.com/langyao/p/7251861.html