알고리즘/SWEA
[SWEA 1204] 최빈수 구하기
히더
2018. 8. 6. 16:58
출처 : https://www.swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV13zo1KAAACFAYh
#include <iostream>
#include <algorithm>
#include <memory.h>
using namespace std;
int result, a, z;
int arr[101];
int main()
{
int T; int t;
cin >> T;
while (T--)
{
cin >> t; result = 0; memset(arr, 0, sizeof(arr)); int n = 1000; z = -1;
while (n--)
{
cin >> a;
arr[a]++;
if (result <= arr[a]) {
if (result == arr[a]) z = max(z, a);
else z = a;
result = arr[a];
}
}
cout << "#" << t << " " << z << endl;
}
return 0;
}