Advertisement
fbinnzhivko

Untitled

Jun 14th, 2016
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.54 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. class FootballStandings
  6. {
  7.     static void Main()
  8.     {
  9.         string key = Console.ReadLine();
  10.         string[] encryptedLine = Console.ReadLine().Split(' ');
  11.         bool isThisTheEnd = encryptedLine[0].ToLower() == "final";
  12.         string[] encryptedLineTeamNames = new string[2];
  13.         int[] encryptedMatchScore = new int[2];
  14.         SortedDictionary<string, int> leagueStanding = new SortedDictionary<string, int>();
  15.         SortedDictionary<string, int> topScorer = new SortedDictionary<string, int>();
  16.         char[] keyLength = key.ToCharArray();
  17.  
  18.  
  19.         while (isThisTheEnd == false)
  20.         {
  21.            SortedDictionary<string, int> matchScore = new SortedDictionary<string, int>();
  22.             encryptedMatchScore = encryptedLine[2].Split(':').Select(int.Parse).ToArray();
  23.  
  24.             for (int i = 0; i < 2; i++)
  25.             {
  26.                 int firstStartPosition = 0;
  27.                 int position = encryptedLine[i].IndexOf(key, firstStartPosition);
  28.                 firstStartPosition = position;
  29.                 int nextStartPosition = firstStartPosition + 1;
  30.  
  31.                 position = encryptedLine[i].IndexOf(key, nextStartPosition);
  32.                 int endtPosition = position;
  33.  
  34.                 string teamName = encryptedLine[i].Substring(firstStartPosition + keyLength.Length, endtPosition - (firstStartPosition + keyLength.Length));
  35.                 char[] teamNamesReverse = teamName.ToCharArray().Reverse().ToArray();
  36.                 encryptedLineTeamNames[i] = string.Join("", teamNamesReverse).ToUpper();
  37.  
  38.                 matchScore.Add(encryptedLineTeamNames[i], encryptedMatchScore[i]);
  39.  
  40.                 if (topScorer.ContainsKey(encryptedLineTeamNames[i]))
  41.                 {
  42.                     topScorer[encryptedLineTeamNames[i]] += matchScore[encryptedLineTeamNames[i]];
  43.                 }
  44.                 else
  45.                 {
  46.                     topScorer.Add(encryptedLineTeamNames[i], encryptedMatchScore[i]);
  47.                 }
  48.  
  49.                 if (i == 1)
  50.                 {
  51.                     if (matchScore[encryptedLineTeamNames[0]] > matchScore[encryptedLineTeamNames[1]])
  52.                     {
  53.                         if (leagueStanding.ContainsKey(encryptedLineTeamNames[0]))
  54.                         {
  55.                             leagueStanding[encryptedLineTeamNames[0]] += 3;
  56.                         }
  57.                         else
  58.                         {
  59.                             leagueStanding.Add(encryptedLineTeamNames[0], 3);
  60.                         }
  61.  
  62.                         if (leagueStanding.ContainsKey(encryptedLineTeamNames[1]))
  63.                         {
  64.                             leagueStanding[encryptedLineTeamNames[1]] += 0;
  65.                         }
  66.                         else
  67.                         {
  68.                             leagueStanding.Add(encryptedLineTeamNames[1], 0);
  69.                         }
  70.                     }
  71.                     else if (matchScore[encryptedLineTeamNames[0]] == matchScore[encryptedLineTeamNames[1]])
  72.                     {
  73.                         if (leagueStanding.ContainsKey(encryptedLineTeamNames[0]))
  74.                         {
  75.                             leagueStanding[encryptedLineTeamNames[0]] += 1;
  76.                         }
  77.                         else
  78.                         {
  79.                             leagueStanding.Add(encryptedLineTeamNames[0], 1);
  80.                         }
  81.  
  82.                         if (leagueStanding.ContainsKey(encryptedLineTeamNames[1]))
  83.                         {
  84.                             leagueStanding[encryptedLineTeamNames[1]] += 1;
  85.                         }
  86.                         else
  87.                         {
  88.                             leagueStanding.Add(encryptedLineTeamNames[1], 1);
  89.                         }
  90.                     }
  91.                     else if (matchScore[encryptedLineTeamNames[0]] < matchScore[encryptedLineTeamNames[1]])
  92.                     {
  93.                         if (leagueStanding.ContainsKey(encryptedLineTeamNames[1]))
  94.                         {
  95.                             leagueStanding[encryptedLineTeamNames[1]] += 3;
  96.                         }
  97.                         else
  98.                         {
  99.                             leagueStanding.Add(encryptedLineTeamNames[1], 3);
  100.                         }
  101.  
  102.                         if (leagueStanding.ContainsKey(encryptedLineTeamNames[0]))
  103.                         {
  104.                             leagueStanding[encryptedLineTeamNames[0]] += 0;
  105.                         }
  106.                         else
  107.                         {
  108.                             leagueStanding.Add(encryptedLineTeamNames[0], 0);
  109.                         }
  110.                     }
  111.                 }
  112.             }
  113.             matchScore.Clear();
  114.             encryptedLine = Console.ReadLine().Split(' ');
  115.             isThisTheEnd = encryptedLine[0].ToLower() == "final";
  116.         }
  117.  
  118.         Console.WriteLine("League standings:");
  119.  
  120.         int counter = 1;
  121.         foreach (var team in leagueStanding.OrderByDescending(team=>team.Value))
  122.         {
  123.             Console.Write("{0}. ", counter);
  124.             Console.WriteLine(team.Key + " " + team.Value);
  125.             counter += 1;
  126.         }
  127.        
  128.         Console.WriteLine("Top 3 scored goals:");
  129.         foreach (var team in topScorer.OrderByDescending(team=>team.Value).Take(3))
  130.         {
  131.             Console.Write(" - ");
  132.             Console.WriteLine("{0} -> {1}", team.Key, team.Value);
  133.         }
  134.     }
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement