/* vim: set ts=4 sts=4 sw=4 si foldmethod=marker: */ // {{{ stock programming challenge garbage // IO #include #include #include #include // Utility #include #include // Data structures //#include #include //#include //#include //#include //#include // Utility typedefs // I want easy access to STL and things like hash_map using namespace std; //using namespace std::tr1; using namespace __gnu_cxx; // Needed for hash_map //namespace __gnu_cxx //{ // template<> struct hash // { // size_t operator()(const std::string& x) const // { // return hash()(x.c_str()); // } // }; //} // }}} struct Attempt { Attempt(char status, int time) : status(status), time(time) { } int time; char status; // C = correct, I = incorrect, otherwise ignore }; typedef list lA; struct Problem { Problem() : solved(false), penalty(0) { } lA attempt; int penalty; bool solved; int solvetime; void solve() { penalty = 0; solved = false; for (lA::iterator i(attempt.begin()); i != attempt.end(); ++i) if ((*i).status == 'C') { if (!solved || (*i).time < penalty) { penalty = (*i).time; solvetime = penalty; solved = true; } } if (solved) for (lA::iterator i(attempt.begin()); i != attempt.end(); ++i) if ((*i).status == 'I' && (*i).time <= solvetime) penalty += 20; } }; struct Contestant { Contestant() : solved(0), penalty(0), number(0), present(false) { } int solved; int penalty; int number; bool present; Problem problem[10]; void solve() { solved = 0; penalty = 0; for (int i(1); i <= 9; i++) { problem[i].solve(); if (problem[i].solved) { solved++; penalty += problem[i].penalty; } } //for ( } }; bool operator<(const Contestant& a, const Contestant& b) { if (a.solved == b.solved) { if (a.penalty == b.penalty) { return a.number < b.number; } else { return a.penalty < b.penalty; } } else return a.solved > b.solved; return (a.solved == b.solved) ? ((a.penalty == b.penalty) ? a.number > b.number : a.penalty > b.penalty) : a.solved > b.solved; } int main(int argc, char **argv) { int cases; cin >> cases; cin.ignore(1000, '\n'); cin.ignore(1000, '\n'); while (cases--) { Contestant contestant[101]; for (int i(1); i <= 100; contestant[i].number = i, ++i); string line; while (getline(cin, line), line != "") { istringstream mystream(line); int team, problem, time; char status; mystream >> team >> problem >> time >> status; contestant[team].present = true; contestant[team].problem[problem].attempt.push_back(Attempt(status, time)); } for (int i(1); i <= 100; ++i) if (contestant[i].present) contestant[i].solve(); sort(contestant + 1, contestant + 101); for (int i(1); i <= 100; ++i) if (contestant[i].present) { cout << contestant[i].number << " " << contestant[i].solved << " " << contestant[i].penalty << endl; } if (0 != cases) cout << endl; } return 0; }