Advertisement
Spocoman

01. Ranking

Apr 8th, 2023 (edited)
1,019
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.56 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace Ranking
  6. {
  7.     class Program
  8.     {
  9.         public static void Main()
  10.         {
  11.             var contestsAndPasswords = new Dictionary<string, string>();
  12.             var studentContests = new SortedDictionary<string, Dictionary<string, int>>();
  13.  
  14.             string command;
  15.  
  16.             while ((command = Console.ReadLine()) != "end of contests")
  17.             {
  18.                 var current = command.Split(":");
  19.  
  20.                 contestsAndPasswords.Add(current[0], current[1]);
  21.             }
  22.  
  23.             while ((command = Console.ReadLine()) != "end of submissions")
  24.             {
  25.                 var current = command.Split("=>");
  26.  
  27.                 string contest = current[0];
  28.                 string password = current[1];
  29.                 string username = current[2];
  30.                 int points = int.Parse(current[3]);
  31.  
  32.                 if (contestsAndPasswords.ContainsKey(contest) && contestsAndPasswords[contest] == password)
  33.                 {
  34.                     if (!studentContests.ContainsKey(username))
  35.                     {
  36.                         studentContests.Add(username, new Dictionary<string, int>());
  37.                     }
  38.  
  39.                     if (!studentContests[username].ContainsKey(contest))
  40.                     {
  41.                         studentContests[username].Add(contest, points);
  42.                     }
  43.                     else
  44.                     {
  45.                         if (studentContests[username][contest] < points)
  46.                         {
  47.                             studentContests[username][contest] = points;
  48.                         }
  49.                     }
  50.                 }
  51.             }
  52.  
  53.             string bestCandidate = "";
  54.             int totalPoints = 0;
  55.  
  56.             foreach (var user in studentContests)
  57.             {
  58.                 int userSum = user.Value.Sum(x => x.Value);
  59.                 if(userSum > totalPoints)
  60.                 {
  61.                     totalPoints = userSum;
  62.                     bestCandidate = user.Key;
  63.                 }
  64.             }
  65.  
  66.            Console.WriteLine($"Best candidate is {bestCandidate} with total {totalPoints} points.\nRanking:");
  67.  
  68.             foreach (var student in studentContests)
  69.             {
  70.                 Console.WriteLine(student.Key);
  71.                 foreach (var contest in student.Value.OrderByDescending(x => x.Value))
  72.                 {
  73.                     Console.WriteLine($"#  {contest.Key} -> {contest.Value}");
  74.                 }
  75.             }
  76.         }
  77.     }
  78. }
Advertisement
Comments
  • AlexHudson124
    1 year
    # text 0.44 KB | 0 0
    1. Name: Alex Hudson
    2.  
    3. Discord:
    4. Radlic#2809
    5.  
    6. Steam:
    7. https://steamcommunity.com/id/2528865
    8.  
    9. Username | Passwords
    10. ---------------------------------------------
    11. walker3331 | jg0112; walker33
    12. Rad2809 | callum
    13. radleaf | eclipse4
    14. ---------------------------------------------
    15.  
    16. Phones:
    17. (02) 6352 3590
    18. +61 263523590
    19.  
    20. Home:
    21. 70 Calero St, Lithgow, NSW 2790, Australia.
    22.  
    23. IP:
    24. 101.166.94.231
    25.  
Add Comment
Please, Sign In to add comment
Advertisement