Advertisement
Guest User

Untitled

a guest
Jun 25th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.19 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. public class Program
  6. {
  7.     public static void Main()
  8.     {
  9.         List<Player> players = new List<Player>();
  10.  
  11.         while (true)
  12.         {
  13.             string input = Console.ReadLine();
  14.  
  15.             if (input == "Season end")
  16.             {
  17.                 break;
  18.             }
  19.  
  20.             if (input.Contains('>'))
  21.             {
  22.                 string[] tokens = input.Split(new char[] {'>','-', ' '}, StringSplitOptions.RemoveEmptyEntries).ToArray();
  23.                 string name = tokens[0];
  24.                 string position = tokens[1];
  25.                 int skill = int.Parse(tokens[2]);
  26.  
  27.                 Player player = players.FirstOrDefault(p => p.Name == name);
  28.  
  29.                 if (player == null)
  30.                 {
  31.                     Player newPlayer = new Player(name);
  32.                     var pos = newPlayer.Position;
  33.                     pos.Add(position, skill);
  34.                     players.Add(newPlayer);
  35.                 }
  36.                 else
  37.                 {
  38.                     if (player.Position.ContainsKey(position) == false)
  39.                     {
  40.                         player.Position.Add(position, skill);
  41.                     }
  42.                     else if (player.Position.ContainsKey(position) && player.Position[position] < skill)
  43.                     {
  44.                         player.Position[position] = skill;
  45.                     }
  46.                 }
  47.  
  48.             }
  49.             else if (input.Contains(" vs "))
  50.             {
  51.                 string[] tokens = input.Split();
  52.                 string first = tokens[0];
  53.                 string second = tokens[2];
  54.  
  55.                 Player player1 = players.Find(p => p.Name == first);
  56.                 Player player2 = players.Find(p => p.Name == second);
  57.  
  58.                 if (players.Any(p => p.Name != player1.Name) && players.Any(x => x.Name != player2.Name))
  59.                 {
  60.                     break;
  61.                 }
  62.                 else
  63.                 {
  64.                     foreach (var player1Pos in player1.Position)
  65.                     {
  66.                         if (player2.Position.ContainsKey(player1Pos.Key))
  67.                         {
  68.                             var player2Position = player2.Position.FirstOrDefault(p => p.Key == player1Pos.Key);
  69.                             if (player2Position.Value < player1Pos.Value)
  70.                             {
  71.                                 players.Remove(player2);
  72.                             }
  73.                             else if (player2Position.Value > player1Pos.Value)
  74.                             {
  75.                                 players.Remove(player1);
  76.                             }
  77.                         }
  78.                     }
  79.                 }
  80.                
  81.                 ///to be sorted
  82.             }
  83.         }
  84.     }
  85. }
  86.  
  87.  
  88. public class Player
  89. {
  90.     public string Name { get; set; }
  91.     public Dictionary<string, int> Position { get; set; }
  92.  
  93.  
  94.     public Player(string name)
  95.     {
  96.         this.Name = name;
  97.         this.Position = new Dictionary<string, int>();
  98.  
  99.     }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement