らての精進日記

修行をします

aoj0028:Mode Value

解法

適当にカウント用の配列を用意して数える。1~100の登場回数の最大値に等しい回数登場した数を出力する。

コード

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

int cnt[100];
int main(){
    int n,ma=0;

    while(cin>>n)ma=max(ma,++cnt[--n]);

    for(int i=0;i<100;i++)
        if(cnt[i]==ma)cout<<i+1<<endl;

   return 0;
}