Advertisement
iliqnvidenov

Untitled

May 23rd, 2015
336
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.73 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. struct Player
  6. {
  7.     public string age;
  8.     public string name;
  9.     public List<string> winOpponents;
  10.     public List<string> lostOpponents;
  11. }
  12.  
  13. class Program
  14. {
  15.     static void Main()
  16.     {
  17.         SortedDictionary<string,Player> notebook = new SortedDictionary<string, Player>();
  18.  
  19.         while (true)
  20.         {
  21.             string input = Console.ReadLine();
  22.             if (input == "END")
  23.             {
  24.                 break;
  25.             }
  26.             string[] line = input.Split('|');
  27.  
  28.             if (!notebook.ContainsKey(line[0]))
  29.             {
  30.                 Player currentPlayer = new Player();
  31.                 switch (line[1])
  32.                 {
  33.                     case "age":
  34.                         currentPlayer.age = line[2];
  35.                         break;
  36.                     case "name":
  37.                         currentPlayer.name = line[2];
  38.                         break;
  39.                     case "win":
  40.                         List<string> opponents = new List<string>();
  41.                         opponents.Add(line[2]);
  42.                         currentPlayer.winOpponents = opponents;
  43.                         break;
  44.                     case "loss":
  45.                         List<string> opponent = new List<string>();
  46.                         opponent.Add(line[2]);
  47.                         currentPlayer.lostOpponents = opponent;
  48.                         break;
  49.                 }
  50.                 notebook.Add(line[0], currentPlayer);
  51.             }
  52.             else
  53.             {
  54.                 string currentColor = line[0];
  55.                 Player currentPlayer = notebook[currentColor];
  56.                 switch (line[1])
  57.                 {
  58.                     case "age":
  59.                         currentPlayer.age = line[2];
  60.                         notebook[currentColor] = currentPlayer;
  61.                         break;
  62.                     case "name":
  63.                         currentPlayer.name = line[2];
  64.                         notebook[currentColor] = currentPlayer;
  65.                         break;
  66.                     case "win":
  67.                         List<string> opponents;
  68.                         if (currentPlayer.winOpponents == null)
  69.                         {
  70.                             opponents = new List<string>();
  71.                         }
  72.                         else
  73.                         {
  74.                             opponents = currentPlayer.winOpponents;
  75.                         }
  76.                         opponents.Add(line[2]);
  77.                         currentPlayer.winOpponents = opponents;
  78.                         notebook[currentColor] = currentPlayer;
  79.                         break;
  80.                     case "loss":
  81.                         List<string> opponent;
  82.                         if (currentPlayer.lostOpponents == null)
  83.                         {
  84.                             opponent = new List<string>();
  85.                         }
  86.                         else
  87.                         {
  88.                             opponent = currentPlayer.lostOpponents;
  89.                         }
  90.                         opponent.Add(line[2]);
  91.                         currentPlayer.lostOpponents = opponent;
  92.                         notebook[currentColor] = currentPlayer;
  93.                         break;
  94.                 }
  95.             }
  96.         }
  97.         //print
  98.         string[] keys = notebook.Keys.ToArray();
  99.         Console.WriteLine();
  100.         for (int i = 0; i < keys.Length; i++)
  101.         {
  102.             string currentKey = keys[i];
  103.             if (notebook[currentKey].name != null && notebook[currentKey].age != null)
  104.             {
  105.                 Console.WriteLine("Color: {0}",currentKey);
  106.                 Console.WriteLine("-age: {0}",notebook[currentKey].age);
  107.                 Console.WriteLine("-name: {0}",notebook[currentKey].name);
  108.                 if (notebook[currentKey].winOpponents != null && notebook[currentKey].lostOpponents != null)
  109.                 {
  110.                     double rank = (notebook[currentKey].winOpponents.Count + 1d)/
  111.                                   (notebook[currentKey].lostOpponents.Count + 1d);
  112.                     List<string> allOponents = notebook[currentKey].winOpponents;
  113.                     foreach (var name in notebook[currentKey].lostOpponents)
  114.                     {
  115.                         allOponents.Add(name);
  116.                     }
  117.                     allOponents.Sort();
  118.                     Console.WriteLine("-opponents: {0}",string.Join(", ",allOponents));
  119.                     Console.WriteLine("-rank: {0:f2}",rank);
  120.                 }
  121.                 else if (notebook[currentKey].winOpponents != null)
  122.                 {
  123.                     double rank = notebook[currentKey].winOpponents.Count + 1d;
  124.                     List<string> allOponents = notebook[currentKey].winOpponents;
  125.                     allOponents.Sort();
  126.                     Console.WriteLine("-opponents: {0}", string.Join(", ", allOponents));
  127.                     Console.WriteLine("-rank: {0:f2}", rank);
  128.                 }
  129.                 else if (notebook[currentKey].lostOpponents != null)
  130.                 {
  131.                     double rank = 1d / (notebook[currentKey].lostOpponents.Count+1d);
  132.                     List<string> allOponents = notebook[currentKey].lostOpponents;
  133.                     allOponents.Sort();
  134.                     Console.WriteLine("-opponents: {0}", string.Join(", ", allOponents));
  135.                     Console.WriteLine("-rank: {0:f2}", rank);
  136.                 }
  137.                 else
  138.                 {
  139.                     Console.WriteLine("-opponents: (empty)");
  140.                     Console.WriteLine("-rank: 1.00");
  141.                 }
  142.             }
  143.         }
  144.     }
  145. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement