Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2018
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.34 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5.  
  6. namespace MOBA_Challenger
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         { //start time 22:41 - solve 80% 00:36 (1:55h) ((celiq test 370/400 in 3:04h)
  12.  
  13.             SortedDictionary<string, Dictionary<string, int>> database = new SortedDictionary<string, Dictionary<string, int>>();
  14.             Dictionary<string, int> totalSkill = new Dictionary<string, int>();
  15.             string[] input = Console.ReadLine().Split().ToArray();
  16.             string commandword = input[0] + " " + input[1];
  17.  
  18.             while (commandword != "Season end")
  19.             {
  20.                 if (input[1] != "vs") // PULNIM
  21.                 {
  22.                     string player = input[0];
  23.                     string position = input[2];
  24.                     int skill = int.Parse(input[4]);
  25.  
  26.                     if (database.ContainsKey(player) == false) // new player
  27.                     {
  28.                         database.Add(player, new Dictionary<string, int>());
  29.                         database[player].Add(position, skill);
  30.                         totalSkill.Add(player, skill);
  31.                     }
  32.                     else
  33.                     {
  34.                         if (database[player].ContainsKey(position) == false) // new position
  35.                         {
  36.                             database[player].Add(position, skill);
  37.                             totalSkill[player] += skill;
  38.                         }
  39.                         else //old position
  40.                         {
  41.                             int oldSKill = database[player][position];
  42.                             if (skill > oldSKill) //higher skill
  43.                             {
  44.                                 database[player][position] = skill;
  45.                                 int diff = skill - oldSKill;
  46.                                 totalSkill[player] += diff;
  47.                             }
  48.                         }
  49.  
  50.                     }
  51.  
  52.                 }
  53.                 else //VERSUS
  54.                 {
  55.                     string player1 = input[0];
  56.                     string player2 = input[2];
  57.                     if (database.ContainsKey(player1))
  58.                     {
  59.                         int p1MMR = totalSkill[player1];
  60.                         int p2MMR = totalSkill[player2];
  61.                         foreach (var role in database[player1])
  62.                         {
  63.                             string p1role = role.Key;
  64.                             if (database.ContainsKey(player2))
  65.                             {
  66.                                 foreach (var role2 in database[player2])
  67.                                 {
  68.                                     string p2role = role2.Key;
  69.  
  70.                                     if (p1role == p2role)
  71.                                     {
  72.                                         if (p1MMR > p2MMR)
  73.                                         {
  74.                                             database.Remove(player2);
  75.                                             totalSkill.Remove(player2); break;
  76.                                         }
  77.                                         else if (p2MMR > p1MMR)
  78.                                         {
  79.                                             database.Remove(player1);
  80.                                             totalSkill.Remove(player1); break;
  81.                                         }
  82.                                     }
  83.                                 }
  84.                             }
  85.                         }
  86.                     }
  87.  
  88.                 }
  89.                 input = Console.ReadLine().Split().ToArray();
  90.                 commandword = input[0] + " " + input[1];
  91.             }
  92.  
  93.  
  94.             //printing
  95.             foreach (var entry in totalSkill.OrderBy(x => -x.Value))
  96.             {
  97.                 string name = entry.Key;
  98.                 int totalMMR = entry.Value;
  99.                 Console.WriteLine($"{name}: {totalMMR} skill");
  100.  
  101.                 foreach (var roleAndMMR in database[name].OrderBy(x => -x.Value))
  102.                 {
  103.                     string role = roleAndMMR.Key;
  104.                     int mmr = roleAndMMR.Value;
  105.                     Console.WriteLine($"- {role} <::> {mmr}");
  106.                 }
  107.  
  108.  
  109.  
  110.  
  111.             }
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.         }
  120.     }
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement