內容
Waterloo大學的新鮮人由於興趣不同,對於課程的選擇不盡相同,而校方希望他們所選的課程盡量一致,所以設立了一個獎項,頒發給 選擇的「課程組合」為「最受歡迎的課程組合」的學生。
輸入說明
輸入有多組測試資料,每組資料的開頭有一個整數 n 表示新生的人數( 1 <= n <= 10000 ),接下來有 n 列分別為這些新生所選擇的課程代號,每列有 5 個表示課程代號的整數,其值介於 100 ~ 499。當 n = 0 表示測試資料結束。
輸出說明
一組課程的受歡迎程度視所有剛好選擇該組課程的學生人數而定,如果沒有其他「課程組合」的人數比此「課程組合」的人數高,則該課程為最 受歡迎的「課程組合」,請對每組測試資料輸出選擇最受歡迎的「課程組合」的人數。
範例輸入 #1
3 100 101 102 103 488 100 200 300 101 102 103 102 101 488 100 3 200 202 204 206 208 123 234 345 456 321 100 200 300 400 444 0
範例輸出 #1
2 3
#include <iostream>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
using namespace std;
int main()
{
int n;
while (cin >> n)
{
if (n == 0)
break;
map<string, int> ans;
vector<int> v(5);
int maxCount = 0;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < 5; j++)
cin >> v[j];
sort(v.begin(), v.end());
string temp;
for (int j = 0; j < 5; j++)
temp += to_string(v[j]);
ans[temp]++;
maxCount = max(maxCount, ans[temp]);
}
int total = 0;
for (auto it = ans.begin(); it != ans.end(); ++it)
{
if (it->second == maxCount)
total += it->second;
}
cout << total << endl;
}
return 0;
}