Advertisement
DyNaMiXx7

Untitled

Mar 27th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.10 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _01Ranking
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             var contests = new Dictionary<string, string>();
  12.             var users = new Dictionary<string, Dictionary<string, int>>();
  13.  
  14.             string input = string.Empty;
  15.             while ((input = Console.ReadLine()) != "end of contests")
  16.             {
  17.                 string[] tokens = input.Split(":");
  18.                 string contest = tokens[0];
  19.                 string passwordForContest = tokens[1];
  20.  
  21.                 contests.Add(contest, passwordForContest);
  22.             }
  23.  
  24.             string secondInput = string.Empty;
  25.             while ((secondInput = Console.ReadLine()) != "end of submissions")
  26.             {
  27.                 string[] tokens = secondInput.Split("=>");
  28.                 string contest = tokens[0];
  29.                 string password = tokens[1];
  30.                 string userName = tokens[2];
  31.                 int points = int.Parse(tokens[3]);
  32.  
  33.                 if (contests.ContainsKey(contest) && contests[contest] == password)
  34.                 {
  35.                     if (!users.ContainsKey(userName))
  36.                     {
  37.                         users.Add(userName, new Dictionary<string, int>());
  38.  
  39.                         if (!users[userName].ContainsKey(contest))
  40.                         {
  41.                             users[userName].Add(contest, points);
  42.                         }
  43.                         else
  44.                         {
  45.                             CheckPoints(users, contest, userName, points);
  46.                         }
  47.                     }
  48.                     else
  49.                     {
  50.                         if (!users[userName].ContainsKey(contest))
  51.                         {
  52.                             users[userName].Add(contest, points);
  53.                         }
  54.                         else
  55.                         {
  56.                             CheckPoints(users, contest, userName, points);
  57.                         }
  58.                     }
  59.                 }
  60.             }
  61.  
  62.             foreach (var item in users.OrderByDescending(x => x.Value.Values.Sum()))
  63.             {
  64.                 Console.WriteLine($"Best candidate is {item.Key} with total {item.Value.Values.Sum()} points.");
  65.                 Console.WriteLine("Ranking: ");
  66.                 foreach (var student in users.OrderBy(x => x.Key[0]))
  67.                 {
  68.                     Console.WriteLine(student.Key);
  69.  
  70.                     foreach (var subjects in student.Value.OrderByDescending(x => x.Value))
  71.                     {
  72.                         Console.WriteLine($"#  {subjects.Key} -> {subjects.Value}");
  73.                     }
  74.                 }
  75.  
  76.                 break;
  77.             }
  78.         }
  79.  
  80.         private static void CheckPoints(Dictionary<string, Dictionary<string, int>> users, string contest, string userName, int points)
  81.         {
  82.             if (points > users[userName][contest])
  83.             {
  84.                 users[userName][contest] = points;
  85.             }
  86.         }
  87.     }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement