Advertisement
Guest User

Untitled

a guest
Nov 25th, 2020
362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.28 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _10._SoftUni_Exam_Results
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             string input = Console.ReadLine();
  12.             Dictionary<string, List<string>> users = new Dictionary<string, List<string>>();
  13.             Dictionary<string, int> languages = new Dictionary<string, int>();
  14.  
  15.             while (!input.Contains("exam finished"))
  16.             {
  17.                 if (input.Contains("banned"))
  18.                 {
  19.                     string[] commandArr = input.Split("-");
  20.                     string bannedUser = commandArr[0];
  21.  
  22.                     users[bannedUser][1] = "banned";
  23.                 }
  24.                 else
  25.                 {
  26.                     string[] commandArr = input.Split("-");
  27.                     string user = commandArr[0];
  28.                     string language = commandArr[1];
  29.                     int score = int.Parse(commandArr[2]);
  30.  
  31.                     if (users.ContainsKey(user))
  32.                     {
  33.                         if (int.Parse(users[user][1]) < score)
  34.                         {
  35.                             users[user][1] = score.ToString();
  36.                         }
  37.                     }
  38.                     else
  39.                     {
  40.                         users.Add(user, new List<string> { language, score.ToString()});
  41.                     }
  42.                     if (languages.ContainsKey(language))
  43.                     {
  44.                         languages[language]++;
  45.                     }
  46.                     else
  47.                     {
  48.                         languages.Add(language, 1);
  49.                     }
  50.                 }
  51.                 input = Console.ReadLine();
  52.             }
  53.             Console.WriteLine("Results:");
  54.             foreach (var user in users.OrderByDescending(x => x.Value[1]).ThenBy(x => x.Key).Where(x => x.Value[1] != "banned"))
  55.             {
  56.                 Console.WriteLine($"{user.Key} | {user.Value[1]}");
  57.             }
  58.             Console.WriteLine("Submissions:");
  59.             foreach (var item in languages.OrderByDescending(x => x.Value).ThenBy(x => x.Key))
  60.             {
  61.                 Console.WriteLine($"{item.Key} - {item.Value}");
  62.             }
  63.         }
  64.     }
  65. }
  66.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement