竹園論壇

標題: 1160 - 3.動態眾數問題 [打印本頁]

作者: Sylveon    時間: 2015-3-30 14:29
標題: 1160 - 3.動態眾數問題
原題:http://tioj.ck.tp.edu.tw/problems/1160
AC:http://tioj.ck.tp.edu.tw/submissions/10529

用map紀錄出現的次數就可以了

[C++] 純文本查看 復制代碼
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstring>
#include<map>
using namespace std;
int main()
{
        ios::sync_with_stdio(false);
        cin.tie(0);
        int N,C;
        int MX=0,TM=0;
        map<int,int> mp;
        while(cin>>N,N)
        {
                C = ++mp[N];
                if( C > TM )
                {
                        TM = C;
                        MX = N;
                }
                else if( C == TM && N < MX )
                        MX = N;
                cout<<TM<<' '<<MX<<'\n';
        }
        return 0;
}







歡迎光臨 竹園論壇 (http://forum.tfcis.org/) Powered by Discuz! X3.2