Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- struct Player
- {
- public string age;
- public string name;
- public List<string> winOpponents;
- public List<string> lostOpponents;
- }
- class Program
- {
- static void Main()
- {
- SortedDictionary<string,Player> notebook = new SortedDictionary<string, Player>();
- while (true)
- {
- string input = Console.ReadLine();
- if (input == "END")
- {
- break;
- }
- string[] line = input.Split('|');
- if (!notebook.ContainsKey(line[0]))
- {
- Player currentPlayer = new Player();
- switch (line[1])
- {
- case "age":
- currentPlayer.age = line[2];
- break;
- case "name":
- currentPlayer.name = line[2];
- break;
- case "win":
- List<string> opponents = new List<string>();
- opponents.Add(line[2]);
- currentPlayer.winOpponents = opponents;
- break;
- case "loss":
- List<string> opponent = new List<string>();
- opponent.Add(line[2]);
- currentPlayer.lostOpponents = opponent;
- break;
- }
- notebook.Add(line[0], currentPlayer);
- }
- else
- {
- string currentColor = line[0];
- Player currentPlayer = notebook[currentColor];
- switch (line[1])
- {
- case "age":
- currentPlayer.age = line[2];
- notebook[currentColor] = currentPlayer;
- break;
- case "name":
- currentPlayer.name = line[2];
- notebook[currentColor] = currentPlayer;
- break;
- case "win":
- List<string> opponents;
- if (currentPlayer.winOpponents == null)
- {
- opponents = new List<string>();
- }
- else
- {
- opponents = currentPlayer.winOpponents;
- }
- opponents.Add(line[2]);
- currentPlayer.winOpponents = opponents;
- notebook[currentColor] = currentPlayer;
- break;
- case "loss":
- List<string> opponent;
- if (currentPlayer.lostOpponents == null)
- {
- opponent = new List<string>();
- }
- else
- {
- opponent = currentPlayer.lostOpponents;
- }
- opponent.Add(line[2]);
- currentPlayer.lostOpponents = opponent;
- notebook[currentColor] = currentPlayer;
- break;
- }
- }
- }
- //print
- string[] keys = notebook.Keys.ToArray();
- Console.WriteLine();
- for (int i = 0; i < keys.Length; i++)
- {
- string currentKey = keys[i];
- if (notebook[currentKey].name != null && notebook[currentKey].age != null)
- {
- Console.WriteLine("Color: {0}",currentKey);
- Console.WriteLine("-age: {0}",notebook[currentKey].age);
- Console.WriteLine("-name: {0}",notebook[currentKey].name);
- if (notebook[currentKey].winOpponents != null && notebook[currentKey].lostOpponents != null)
- {
- double rank = (notebook[currentKey].winOpponents.Count + 1d)/
- (notebook[currentKey].lostOpponents.Count + 1d);
- List<string> allOponents = notebook[currentKey].winOpponents;
- foreach (var name in notebook[currentKey].lostOpponents)
- {
- allOponents.Add(name);
- }
- allOponents.Sort();
- Console.WriteLine("-opponents: {0}",string.Join(", ",allOponents));
- Console.WriteLine("-rank: {0:f2}",rank);
- }
- else if (notebook[currentKey].winOpponents != null)
- {
- double rank = notebook[currentKey].winOpponents.Count + 1d;
- List<string> allOponents = notebook[currentKey].winOpponents;
- allOponents.Sort();
- Console.WriteLine("-opponents: {0}", string.Join(", ", allOponents));
- Console.WriteLine("-rank: {0:f2}", rank);
- }
- else if (notebook[currentKey].lostOpponents != null)
- {
- double rank = 1d / (notebook[currentKey].lostOpponents.Count+1d);
- List<string> allOponents = notebook[currentKey].lostOpponents;
- allOponents.Sort();
- Console.WriteLine("-opponents: {0}", string.Join(", ", allOponents));
- Console.WriteLine("-rank: {0:f2}", rank);
- }
- else
- {
- Console.WriteLine("-opponents: (empty)");
- Console.WriteLine("-rank: 1.00");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement