Advertisement
silentkiler029

UVA-10258-Contest_Scoreboard-By_Shanto

Jun 25th, 2020
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.64 KB | None | 0 0
  1. /*  BISMILLAHIR-RAHMANIR-RAHIM
  2.  ____________________________________
  3. |                                    |
  4. |       SHANTO_SUST_SWE-19_029       |
  5. |____________________________________|
  6. */
  7.  
  8. #include <bits/stdc++.h>
  9.  
  10. using namespace std;
  11.  
  12. #define ll long long
  13. #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  14. #define pb push_back
  15. #define Pi acos(-1)
  16. #define r0 return 0
  17. #define endl "\n"
  18. #define show(x) cout << x << endl
  19. #define take(x) cin >> x
  20. #define debug 1
  21.  
  22. int main()
  23. {
  24.     int T, t = 0;
  25.     cin >> T;
  26.     getchar();
  27.     getchar();
  28.  
  29.     string s;
  30.     int solved[101][11]; //if nth one is solved
  31.     int penalty[101][11];
  32.     int submitted[101]; //if submitted
  33.     int correct[101]; //total solved
  34.     int tot_pen[101];
  35.     int index[101];
  36.     int id, p, n;
  37.     int i, j, len, temp;
  38.     string ID, pen, num;
  39.     char ch;
  40.  
  41.     while(T--) {
  42.         t++;
  43.         for(i = 0; i < 101; i++) {
  44.             for(j = 0; j < 11; j++) {
  45.                 solved[i][j] = 0;
  46.                 penalty[i][j] = 0;
  47.             }
  48.             submitted[i] = 0;
  49.             correct[i] = 0;
  50.             tot_pen[i] = 0;
  51.             index[i] = i;
  52.         }
  53.  
  54.         while(1) {
  55.             getline(cin, s);
  56.             if(s.size() == 0) {
  57.                 break;
  58.             }
  59.             //till now OKAY!
  60.             len = s.size();
  61.             //ID
  62.             for(i = 0; i < len; i++) {
  63.                 if(s[i] == ' ') {
  64.                     break;
  65.                 }
  66.                 ID.pb(s[i]);
  67.             }
  68.             i++;
  69.             //Problem Number
  70.             for( ; ; i++) {
  71.                 if(s[i] == ' ') {
  72.                     break;
  73.                 }
  74.                 num.pb(s[i]);
  75.             }
  76.             i++;
  77.             //Penalty
  78.             for( ; ; i++) {
  79.                 if(s[i] == ' ') {
  80.                     break;
  81.                 }
  82.                 pen.pb(s[i]);
  83.             }
  84.             i++;
  85.             ch = s[len-1];
  86.  
  87.  
  88.             int m = 1;
  89.  
  90.             //calculating id
  91.             m = 1;
  92.             id = 0;
  93.             for(i = ID.size() - 1; i >= 0; i--) {
  94.                 id += (s[i] - '0') * m;
  95.                 m *= 10;
  96.             }
  97.             submitted[id] = 1;
  98.             //calculating n
  99.             m = 1;
  100.             n = 0;
  101.             for(i = num.size() - 1; i >= 0; i--) {
  102.                 n += (num[i] - '0') * m;
  103.                 m *= 10;
  104.             }
  105.             //calculating p
  106.             m = 1;
  107.             p = 0;
  108.             for(i = pen.size() - 1; i >= 0; i--) {
  109.                 p += (pen[i] - '0') * m;
  110.                 m *= 10;
  111.             }
  112.  
  113.             if( ch == 'R' || ch == 'U' || ch == 'E' ) {
  114.                 ID.clear();
  115.                 num.clear();
  116.                 pen.clear();
  117.                 continue;
  118.             }
  119.  
  120.             else if(ch == 'C') {
  121.                 if(solved[id][n] != 1) {
  122.                     penalty[id][n] += p;
  123.                 }
  124.                 solved[id][n] = 1;
  125.             }
  126.             else if(ch == 'I') {
  127.                 if(solved[id][n] != 1) {
  128.                     penalty[id][n] += 20;
  129.                 }
  130.             }
  131.  
  132.             ID.clear();
  133.             num.clear();
  134.             pen.clear();
  135.         }
  136.         //counting tot_penalty and correct array
  137.         for(i = 1; i < 101; i++) {
  138.             if(submitted[i]) {
  139.                 for(j = 1; j < 11; j++) {
  140.                     if(solved[i][j] == 1) {
  141.                         correct[i]++;
  142.                         tot_pen[i] += penalty[i][j];
  143.                     }
  144.                 }
  145.             }
  146.         }
  147.         //Now we will sort
  148.         //most solved (correct)
  149.         for(i = 1; i < 101; i++) {
  150.             for(j = i + 1; j < 101; j++) {
  151.                 if(correct[index[i]] < correct[index[j]]) {
  152.                     temp = index[i];
  153.                     index[i] = index[j];
  154.                     index[j] = temp;
  155.                 }
  156.             }
  157.         }
  158.         //penalty
  159.         int l = 1, r, j, k;
  160.         for(i = 1; i < 101; i++) {
  161.             if(i == 100) {
  162.                 r = 101;
  163.                 for(j = l; j < r; j++) {
  164.                     for(k = j + 1; k < r; k++) {
  165.                         if(tot_pen[index[j]] > tot_pen[index[k]]) {
  166.                             //switch
  167.                             cout << "j,k = " << index[j] << "," << index[k] << endl;
  168.                             temp = index[k];
  169.                             index[k] = index[j];
  170.                             index[j] = temp;
  171.                         }
  172.                     }
  173.                 }
  174.             }
  175.             else if(correct[index[l]] != correct[index[i]]) {
  176.                 r = i;
  177.                 for(j = l; j < r; j++) {
  178.                     for(k = j + 1; k < r; k++) {
  179.                         if( (tot_pen[index[j]] > tot_pen[index[k]]) ) {
  180.                             //switch
  181.                             temp = index[k];
  182.                             index[k] = index[j];
  183.                             index[j] = temp;
  184.                         }
  185.                     }
  186.                 }
  187.                 l = r;
  188.             }
  189.         }
  190.         //index
  191.         l = 1;
  192.         for(i = 1; i < 101; i++) {
  193.             if(i == 100) {
  194.                 r = 101;
  195.                 for(j = l; j < r; j++) {
  196.                     for(k = j + 1; k < r; k++) {
  197.                         if( (correct[index[j]] == correct[index[k]]) &&
  198.                            (index[j] > index[k]) ) {
  199.                             //switch
  200.                             temp = index[k];
  201.                             index[k] = index[j];
  202.                             index[j] = temp;
  203.                         }
  204.                     }
  205.                 }
  206.             }
  207.             else if(tot_pen[index[l]] != tot_pen[index[i]]) {
  208.                 r = i;
  209.                 for(j = l; j < r; j++) {
  210.                     for(k = j + 1; k < r; k++) {
  211.                         if( (correct[index[j]] == correct[index[k]]) &&
  212.                            (index[j] > index[k]) ) {
  213.                             //switch
  214.                             temp = index[k];
  215.                             index[k] = index[j];
  216.                             index[j] = temp;
  217.                         }
  218.                     }
  219.                 }
  220.                 l = r;
  221.             }
  222.         }
  223.         //sorted
  224.  
  225.         if(t != 1) {
  226.             cout << endl;
  227.         }
  228.  
  229.         for(i = 1; i < 101; i++) {
  230.             if(submitted[index[i]]) {
  231.                 cout << index[i] << " " << correct[index[i]] << " " << tot_pen[index[i]] << endl;
  232.             }
  233.         }
  234.  
  235.     }
  236.  
  237.  
  238.     r0;
  239. }
  240.  
  241. //ALHAMDULILLAH
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement