Computer Programming Contest Preparation

ToolBox - Source for: 112/11286/a.cpp



/home/toolbox/public_html/solutions/112/11286/a.cpp
    1 #include <iostream>
    2 #include <algorithm>
    3 #include <map>
    4 
    5 using namespace std;
    6 
    7 int main(void)
    8 {
    9     int num_students;
   10     map<unsigned long long, int> list;
   11     cin >> num_students;
   12     while(num_students != 0)
   13         {
   14             int max = 1;
   15             int answer = 0;
   16             for (int x = 0; x< num_students; x++)
   17                 {
   18                     int in[5];
   19                     cin >> in[0];
   20                     cin >> in[1];
   21                     cin >> in[2];
   22                     cin >> in[3];
   23                     cin >> in[4];
   24                     sort(in, in + 5);
   25                     unsigned long long total = 0;
   26                     for (int y = 0; y< 5 ; y++)
   27                         {
   28                             total = total*1000 + in[y];
   29                         }
   30                     map<unsigned long long, int>::iterator end = list.end();
   31                     if(list.find(total) != end)
   32                         {
   33                             list[total]++;
   34                             if(max < list[total])
   35                                 {
   36                                     max = list[total];
   37                                 }
   38                         }
   39                     else
   40                         {
   41                             list.insert(pair<unsigned long long, int>(total, 1));
   42                         }
   43                     //cout << total << endl;
   44                 }
   45             map<unsigned long long, int>::iterator it;
   46             map<unsigned long long, int>::iterator end = list.end();
   47             //cout << "MAX IS : " << max << endl;
   48             for(it = list.begin(); it != end; ++it)
   49                 {
   50                     //cout << "Map: (" << it->first << ", " << it->second << ")" << endl;
   51                     if(max == it->second) answer += max;
   52                 }
   53             cout << answer << endl;
   54             //cout << "-----------" << endl;
   55             cin >> num_students;
   56             list.clear();
   57         }
   58 }
   59