【題目敘述】https://zerojudge.tw/ShowProblem?problemid=b265
【解題想法】Hash
- 因為課程代號是三位數字,且每位學生都修5門課。把5個課程代號排序後串接在一起,當成key。
- 【例】103, 102, 101, 488, 100
- 排序後:100, 101, 102, 103, 488
- 串接在一起:100101102103488 (不會超出long long的範圍)
- 當成map的key,mp[100101102103488]++
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
int main() {
int n;
long long course;
while (cin >> n && n){
int a[5];
map<long long, int> mp;
for (int i = 0; i < n; i++){
for (int j = 0; j < 5; j++){
cin >> a[j];
}
sort(a, a+5);
course = 0LL;
for (int j = 0; j < 5; j++){
course *= 1000;
course += a[j];
}
mp[course]++;
}
int mx = 0;
for (auto i: mp){
mx = max(mx, i.second);
}
int ans = 0;
for (auto i: mp){
if (i.second == mx) ans += mx;
}
cout << ans << "\n";
}
return 0;
}