Advertisement
diyanborisov

TheFootbalStatician

Jan 11th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.67 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7.  
  8. //You should make a league table only for one of the leagues.
  9. //It consists of 8 teams: Arsenal, Chelsea, Manchester City,
  10. //Manchester United, Liverpool, Everton, Southampton and Tottenham.
  11.  
  12. //You are given a string in the format ″team1 outcome team2″ separated by one or more whitespaces.
  13. //The outcome of the match will be one of the characters [1, X, 2].
  14. //The character ′1′ represents a win for team1,
  15. //the character ′2′ represents a win for team2 and ′X′ represents draw.
  16. //When one of the teams wins, it receives 3 points. The other team receives 0 points.
  17. //In case of a draw the both teams receive 1 point.
  18.  
  19. //Mr. Vulchan will pay you N euros for every match.
  20. //You should evaluate how much money you will obtain for this job and print it on the console in leva.
  21. //Assume that 1 euro is 1.94lv.
  22.  
  23. //Input
  24. //The input data should be read from the console.
  25. //On the first line you will receive the payment for every match.
  26. //On the next N lines you are given several input lines holding the match and its result.
  27. //When you receive the command “End of the league.” the program should stop.
  28. //The input data will always be valid and in the format described. There is no need to check it explicitly.
  29.  
  30. //Output
  31. //The output data should be printed on the console.
  32. //On the first line you should print the evaluated price for all matches in the league in leva
  33. //rounded to two digits after the decimal point.
  34. //On the next 8 lines you should print all the teams in alphabetical order,
  35. //each on a separate line, together with the points, they have gained.
  36.  
  37. //Constraints
  38. //The payment will be a floating point number in the range (-7.9 x 1028 to 7.9 x 1028) / (100 to 1028)
  39. //Allowed working time for your program: 0.1 seconds.
  40. //Allowed memory: 16 MB.
  41.  
  42. //Hint: The teams with more than one word are represented without spacing in Pascal case.
  43.  
  44. class TheFootballStatistician
  45. {
  46.     static void Main()
  47.     {
  48.         decimal everyMatchPayment = decimal.Parse(Console.ReadLine());
  49.         int counterMatch = 0;
  50.         string teamOne;
  51.         string teamTwo;
  52.         string outcome;
  53.         Dictionary<string, int> teamsResult = new Dictionary<string, int>();
  54.         while (true)
  55.         {
  56.             string inputMatch = Console.ReadLine();
  57.             if (inputMatch == "End of the league.")
  58.             {
  59.                 break;
  60.             }
  61.             counterMatch++;
  62.             string[] matchResult = inputMatch.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
  63.             teamOne = matchResult[0];
  64.             teamTwo = matchResult[2];
  65.             outcome = matchResult[1];
  66.  
  67.             if (outcome == "1")
  68.             {
  69.                 if (teamsResult.ContainsKey(teamOne))
  70.                 {
  71.                     teamsResult[teamOne] += 3;
  72.                 }
  73.                 else
  74.                 {
  75.                     teamsResult.Add(teamOne, 3);
  76.                 }
  77.                 if (teamsResult.ContainsKey(teamTwo))
  78.                 {
  79.                     teamsResult[teamTwo] += 0;
  80.                 }
  81.                 else
  82.                 {
  83.                     teamsResult.Add(teamTwo, 0);
  84.                 }
  85.             }
  86.             if (outcome == "2")
  87.             {
  88.                 if (teamsResult.ContainsKey(teamTwo))
  89.                 {
  90.                     teamsResult[teamTwo] += 3;
  91.                 }
  92.                 else
  93.                 {
  94.                     teamsResult.Add(teamTwo, 3);
  95.                 }
  96.                 if (teamsResult.ContainsKey(teamOne))
  97.                 {
  98.                     teamsResult[teamOne] += 0;
  99.                 }
  100.                 else
  101.                 {
  102.                     teamsResult.Add(teamOne, 0);
  103.                 }
  104.             }
  105.             if (outcome == "X")
  106.             {
  107.                 if (teamsResult.ContainsKey(teamOne))
  108.                 {
  109.                     teamsResult[teamOne] += 1;
  110.                 }
  111.                 else
  112.                 {
  113.                     teamsResult.Add(teamOne, 1);
  114.                 }
  115.                 if (teamsResult.ContainsKey(teamTwo))
  116.                 {
  117.                     teamsResult[teamTwo] += 1;
  118.                 }
  119.                 else
  120.                 {
  121.                     teamsResult.Add(teamTwo, 1);
  122.                 }
  123.             }
  124.         }
  125.         Console.WriteLine("{0:F2}lv.",counterMatch*(everyMatchPayment*1.94m));
  126.         foreach (var team in teamsResult.OrderBy(i => i.Key))
  127.         {
  128.            
  129.             Console.WriteLine("{0} - {1} points.",team.Key,team.Value);
  130.         }
  131.     }
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement