Advertisement
Guest User

HandballStat

a guest
May 25th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.02 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. class Handball1
  5. {
  6.     static void Main()
  7.     {
  8.         string input = Console.ReadLine();
  9.  
  10.         Dictionary<string, Dictionary<string, int>> teamOpponentsWinOrNo = new Dictionary<string, Dictionary<string, int>>();
  11.  
  12.         while (true)
  13.         {
  14.             if (input == "stop")
  15.             {
  16.                 break;
  17.             }
  18.  
  19.             string[] line = input
  20.                 .Split(" | ", StringSplitOptions.RemoveEmptyEntries)
  21.                 .ToArray();
  22.  
  23.             int[] team1Team2Points = line[2]
  24.                 .Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries)
  25.                 .Select(int.Parse)
  26.                 .ToArray();
  27.  
  28.             int[] team2Team1Points = line[3]
  29.                 .Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries)
  30.                 .Select(int.Parse)
  31.                 .ToArray();
  32.  
  33.             string team1 = line[0];
  34.             string team2 = line[1];
  35.  
  36.             int team1Home = team1Team2Points[0];
  37.             int team2Guest = team1Team2Points[1];
  38.             int team2Home = team2Team1Points[0];
  39.             int team1Guest = team2Team1Points[1];
  40.  
  41.             int team1WinOrNo = 0;
  42.             int team2WinOrNo = 0;
  43.  
  44.             int team1Points = team1Home + team1Guest;
  45.             int team2Points = team2Home + team2Guest;
  46.  
  47.             if (team1Points > team2Points || ((team1Points == team2Points) && team1Guest > team2Guest))
  48.             {
  49.                 team1WinOrNo = 1;
  50.             }
  51.             else
  52.             {
  53.                 team2WinOrNo = 1;
  54.             }
  55.  
  56.             if (!teamOpponentsWinOrNo.ContainsKey(team1))
  57.             {
  58.                 Dictionary<string, int> current = new Dictionary<string, int>();
  59.                 current.Add(team2, team1WinOrNo);
  60.                 teamOpponentsWinOrNo.Add(team1, current);
  61.             }
  62.             else
  63.             {
  64.                 teamOpponentsWinOrNo[team1].Add(team2, team1WinOrNo);
  65.             }
  66.  
  67.             if (!teamOpponentsWinOrNo.ContainsKey(team2))
  68.             {
  69.                 Dictionary<string, int> current1 = new Dictionary<string, int>();
  70.                 current1.Add(team1, team2WinOrNo);
  71.                 teamOpponentsWinOrNo.Add(team2, current1);
  72.             }
  73.             else
  74.             {
  75.                 teamOpponentsWinOrNo[team1].Add(team1, team2WinOrNo);
  76.             }
  77.  
  78.             input = Console.ReadLine();
  79.         }
  80.  
  81.         foreach (var kvp in teamOpponentsWinOrNo.OrderByDescending(x => x.Value.Values.Sum()).ThenBy(y => y.Key))
  82.         {
  83.             Console.WriteLine($"{kvp.Key}");
  84.             Console.WriteLine($"- Wins: {kvp.Value.Values.Sum()}");
  85.  
  86.             List<string> opponents = new List<string>();
  87.             foreach (var item in kvp.Value)
  88.             {
  89.                 opponents.Add(item.Key);
  90.             }
  91.  
  92.             Console.Write($"- Opponents: ");
  93.             Console.WriteLine($"{string.Join(", ", opponents.OrderBy(z => z))}");
  94.         }
  95.     }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement