1 // BEGIN CUT HERE
2
3 // END CUT HERE
4 #include <functional>
5 #include <algorithm>
6 #include <stdexcept>
7 #include <iostream>
8 #include <sstream>
9 #include <fstream>
10 #include <iomanip>
11 #include <cstdlib>
12 #include <cstring>
13 #include <utility>
14 #include <cctype>
15 #include <vector>
16 #include <string>
17 #include <bitset>
18 #include <queue>
19 #include <stack>
20 #include <ctime>
21 #include <list>
22 #include <map>
23 #include <set>
24 #include <math.h>
25
26 using namespace std;
27
28 #define pb push_back
29 #define INF 100000000000
30 #define L(s) (int)((s).size())
31 #define FOR(i,a,b) for (int _n(b), i(a); i<=_n; i++)
32 #define rep(i,n) FOR(i,1,(n))
33 #define rept(i,n) FOR(i,0,(n)-1)
34 #define rept2(i, m, j, n) FOR(i, 0, (m)-1) FOR(j, 0, (n)-1)
35 #define rep2(i, m, j, n) FOR(i, 1, (m)) FOR(j, 1, (n))
36 #define C(a) memset((a), 0, sizeof(a))
37 #define ll long long
38 #define VI vector<int>
39 #define ppb pop_back
40 #define mp make_pair
41 #define MOD 1000000007
42 int toInt(string s){ istringstream sin(s); int t; sin>>t;return t;}
43
44 double stringToDouble(string s) {
45 double ret = 0.0;
46 rept(i, L(s)) {
47 if (s[i] != '.') ret = ret*10 + int(s[i]-'0');
48 else break;
49 }
50 ret += 0.10*(s[L(s)-1]-'0');
51 int t = int(ret*10+0.5);
52 ret = double(t)/10;
53 return ret;
54 }
55
56 string intToString(int n) {
57 string ret;
58 if (n == 0) return "0";
59 while (n) {
60 char tmp = char('0' + n%10);
61 ret += tmp;
62 n /= 10;
63 }
64 reverse(ret.begin(), ret.end());
65 return ret;
66 }
67
68 string doubleToString(double n) {
69 string ret;
70 int t = int(n*10+0.5);
71 n = double(t)/10;
72 if (n == 0.0) return "0.0";
73 int m = int(n*10);
74 while (m) {
75 char tmp = char('0' + m%10);
76 ret += tmp;
77 m /= 10;
78 }
79 if (n < 1.0) ret += '0';
80 reverse(ret.begin(), ret.end());
81 ret.insert(L(ret)-1, ".");
82 return ret;
83 }
84
85 void getInfo(vector<string> &data, vector<string> &name, vector<vector<double> > &score) {
86 rept(i, L(data)) {
87 vector<double> ps;
88 int cur = 0;
89 string savetmp = "";
90 while (data[i][cur] != ' ') {
91 savetmp += data[i][cur];
92 cur++;
93 }
94 name.pb(savetmp);
95 string tmp;
96 while (cur != L(data[i])) {
97 tmp = "";
98 cur++;
99 while (data[i][cur] != ' ') {
100 tmp += data[i][cur];
101 cur++;
102 if (cur == L(data[i])) break;
103 }
104 ps.pb(stringToDouble(tmp));
105 }
106 score.pb(ps);
107 }
108 }
109 struct node {
110 int ranknum;
111 double sco;
112 string name;
113 node(int a, double b, string c) : ranknum(a), sco(b), name(c) { }
114 node() : ranknum(0), sco(0.0), name("") { }
115 };
116
117 bool cmp(const double a, const double b) {return a > b;}
118 bool comp(const struct node a, const struct node b) {
119 if (a.ranknum == b.ranknum) return a.name < b.name;
120 else return a.ranknum < b.ranknum;
121 }
122
123
124
125 class ContestScore
126 {
127 public:
128
129 vector <string> sortResults(vector <string> data)
130 {
131 vector<vector<double> > score;
132 vector<string> name;
133 getInfo(data, name, score);
134 map<double, int> S;
135 vector<double> T(L(score));
136 vector<vector<int> > rankrec(L(score), vector<int>(L(score[0])));
137 for (int j = 0; j < score[0].size(); j++) {
138 rept(i, L(score)) {
139 S[score[i][j]] = i;
140 T[i] = score[i][j];
141 }
142 sort(T.begin(), T.end(), cmp);
143 rept(i, L(score)) rankrec[S[T[i]]][j] = i + 1;
144 }
145 vector<node> res;
146 for (int i = 0; i < L(score); i++) {
147 node tmp(0, 0.0, name[i]);
148 for (int j = 0; j < L(score[0]); j++) {
149 tmp.ranknum += rankrec[i][j];
150 tmp.sco += score[i][j];
151 }
152 res.pb(tmp);
153 }
154 sort(res.begin(), res.end(), comp);
155 vector<string> ret;
156 rept(i, L(score)) {
157 string tmp;
158 tmp += res[i].name;
159 tmp += ' ';
160 tmp += intToString(res[i].ranknum);
161 tmp += ' ';
162 tmp += doubleToString(res[i].sco);
163 ret.pb(tmp);
164 }
165 return ret;
166 }
167
168 // BEGIN CUT HERE
169 public:
170 void run_test(int Case) { if ((Case == -1) || (Case == 0)) test_case_0(); if ((Case == -1) || (Case == 1)) test_case_1(); if ((Case == -1) || (Case == 2)) test_case_2(); if ((Case == -1) || (Case == 3)) test_case_3(); if ((Case == -1) || (Case == 4)) test_case_4(); }
171 private:
172 template <typename T> string print_array(const vector<T> &V) { ostringstream os; os << "{ "; for (typename vector<T>::const_iterator iter = V.begin(); iter != V.end(); ++iter) os << '\"' << *iter << "\","; os << " }"; return os.str(); }
173 void verify_case(int Case, const vector <string> &Expected, const vector <string> &Received) { cerr << "Test Case #" << Case << "..."; if (Expected == Received) cerr << "PASSED" << endl; else { cerr << "FAILED" << endl; cerr << "\tExpected: " << print_array(Expected) << endl; cerr << "\tReceived: " << print_array(Received) << endl; } }
174 void test_case_0() { string Arr0[] = {"A 90.7 92.9 87.4",
175 "B 90.5 96.6 88.0",
176 "C 92.2 91.0 95.3"}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); string Arr1[] = { "C 5 278.5", "B 6 275.1", "A 7 271.0" }; vector <string> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); verify_case(0, Arg1, sortResults(Arg0)); }
177 void test_case_1() { string Arr0[] = {"STANFORD 85.3 90.1 82.6 84.6 96.6 94.5 87.3 90.3",
178 "MIT 95.5 83.9 80.4 85.5 98.7 98.3 96.7 82.7",
179 "PRINCETON 99.2 79.1 87.6 85.1 93.6 96.4 86.0 90.6",
180 "HARVARD 83.6 92.0 85.5 94.3 97.5 91.5 92.5 83.0",
181 "YALE 99.5 92.6 86.2 82.0 96.4 92.6 84.5 78.6",
182 "COLUMBIA 97.2 87.6 81.7 93.7 88.0 86.3 95.9 89.6",
183 "BROWN 92.2 95.8 92.1 81.5 89.5 87.0 95.5 86.4",
184 "PENN 96.3 80.7 81.2 91.6 85.8 92.2 83.9 87.8",
185 "CORNELL 88.0 83.7 85.0 83.8 99.8 92.1 91.0 88.9"}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); string Arr1[] = { "PRINCETON 34 717.6", "MIT 36 721.7", "HARVARD 38 719.9", "COLUMBIA 39 720.0", "STANFORD 39 711.3", "YALE 40 712.4", "BROWN 41 720.0", "CORNELL 42 712.3", "PENN 51 699.5" }; vector <string> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); verify_case(1, Arg1, sortResults(Arg0)); }
186 void test_case_2() { string Arr0[] = {"A 00.1", "B 05.2", "C 29.0","D 00.0"}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); string Arr1[] = { "C 1 29.0", "B 2 5.2", "A 3 0.1", "D 4 0.0" }; vector <string> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); verify_case(2, Arg1, sortResults(Arg0)); }
187 void test_case_3() { string Arr0[] = {"AA 90.0 80.0 70.0 60.0 50.0 40.0",
188 "BBB 80.0 70.0 60.0 50.0 40.0 90.0",
189 "EEE 70.0 60.0 50.0 40.0 90.0 80.0",
190 "AAA 60.0 50.0 40.0 90.0 80.0 70.0",
191 "DDD 50.0 40.0 90.0 80.0 70.0 60.0",
192 "CCC 40.0 90.0 80.0 70.0 60.0 50.0"}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); string Arr1[] = { "AA 21 390.0", "AAA 21 390.0", "BBB 21 390.0", "CCC 21 390.0", "DDD 21 390.0", "EEE 21 390.0" }; vector <string> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); verify_case(3, Arg1, sortResults(Arg0)); }
193 void test_case_4() { string Arr0[] = {"A 00.1", "B 05.2", "C 29.0","D 00.0"}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); string Arr1[] = { "C 1 29.0", "B 2 5.2", "A 3 0.1", "D 4 0.0" }; vector <string> Arg1(Arr1, Arr1 + (sizeof(Arr1) / sizeof(Arr1[0]))); verify_case(4, Arg1, sortResults(Arg0)); }
194
195 // END CUT HERE
196
197 };
198 // BEGIN CUT HERE
199 int main()
200 {
201 ContestScore ___test;
202 ___test.run_test(-1);
203 return 0;
204 }
205 // END CUT HERE