Advertisement
MiinaMagdy

10258 - Contest Scoreboard

Sep 11th, 2022
827
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.98 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define ll long long
  6. #define endl '\n'
  7. #define sz(x) int(x.size())
  8. #define all(x) x.begin(), x.end()
  9.  
  10. struct Status {
  11.     bool solved;
  12.     int penality;
  13.     Status() {
  14.         solved = false;
  15.         penality = 0;
  16.     }
  17. };
  18.  
  19. struct Judge {
  20.     int contestant;
  21.     vector<Status> problems;
  22.     bool participating;
  23.     Judge() {
  24.         participating = false;
  25.         problems.assign(10, Status());
  26.     }
  27.     int solved_problems() const {
  28.         int cnt = 0;
  29.         for (int i = 1; i <= 9; i++) cnt += problems[i].solved;
  30.         return cnt;
  31.     }
  32.     int penality() const {
  33.         int pena = 0;
  34.         for (int i = 1; i <= 9; i++) {
  35.             pena += (problems[i].solved * problems[i].penality);
  36.         }
  37.         return pena;
  38.     }
  39.     bool operator<(Judge const & rhs) {
  40.         int cnt_i = solved_problems(), cnt_r = rhs.solved_problems();
  41.         return cnt_i > cnt_r || ((cnt_i == cnt_r && penality() < rhs.penality()) || (penality() == rhs.penality() && contestant < rhs.contestant));
  42.     }
  43. };
  44.  
  45. int main() {
  46.     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  47.     int test;
  48.     cin >> test;   
  49.     cin.ignore();
  50.     cin.ignore();
  51.     int cnt = 0;
  52.     while (test--) {
  53.         if (cnt++) cout << endl;
  54.         vector<Judge> standing(105);
  55.         string s;
  56.         while (getline(cin, s), isdigit(s[0])) {
  57.             stringstream ss(s);
  58.             int person, problem, time;
  59.             char L;
  60.             ss >> person >> problem >> time >> L;
  61.             standing[person].participating = true;
  62.             standing[person].contestant = person;
  63.             if (L == 'C') {
  64.                 if (standing[person].problems[problem].solved) continue;
  65.                 standing[person].problems[problem].solved = true;
  66.                 standing[person].problems[problem].penality += time;
  67.             }
  68.             else if (L == 'I') {
  69.                 if (standing[person].problems[problem].solved) continue;
  70.                 standing[person].problems[problem].penality += 20;
  71.             }
  72.         }
  73.         sort(all(standing));
  74.         for (int i = 0; i < 105; i++) {
  75.             if (standing[i].participating) {
  76.                 cout << standing[i].contestant << " " << standing[i].solved_problems() << " " << standing[i].penality() << endl;
  77.             }
  78.         }
  79.     }
  80. }
  81.  
Tags: UVA CP3
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement