settingsAccountsettings
Menusettings

Q: The Football Statistician - C# Task

+4 votes

Mr. Vulchan is a football statistician and his daily job is to watch football matches, collect the results and prepare a table of the league. Unfortunately, one day he fell off a cliff and hit his head badly. From that day he can’t remember any numbers and he needs some help with them. Your task is to prepare the league table for him. Since you are very good at programming, you decide to make a program to do this.

You should make a league table only for one of the leagues. It consists of 8 teams: Arsenal, Chelsea, Manchester City, Manchester United, Liverpool, Everton, Southampton and Tottenham.

You are given a string in the format ″team1 outcome team2″ separated by one or more whitespaces. The outcome of the match will be one of the characters [1, X, 2]. The character ′1′ represents a win for team1, the character ′2′ represents a win for team2 and ′X′ represents draw.

  • When one of the teams wins, it receives 3 points. The other team receives 0 points.
  • In case of a draw the both teams receive 1 point.

Mr. Vulchan will pay you N euros for every match. You should evaluate how much money you will obtain for this job and print it on the console in leva. Assume that 1 euro is 1.94lv.

Input

The input data should be read from the console.

  • On the first line you will receive the payment for every match.
  • On the next N lines you are given several input lines holding the match and its result. When you receive the command “End of the league.” the program should stop.

The input data will always be valid and in the format described. There is no need to check it explicitly.

Output

The output data should be printed on the console.

  • On the first line you should print the evaluated price for all matches in the league in leva rounded to two digits after the decimal point.
  • On the next 8 lines you should print all the teams in alphabetical order, each on a separate line, together with the points, they have gained.

Constraints

  • The payment will be a floating point number in the range (-7.9 x 1028 to 7.9 x 1028) / (100 to 1028)
  • Allowed working time for your program: 0.1 seconds.
  • Allowed memory: 16 MB.
  • Hint: The teams with more than one word are represented without spacing in Pascal case.

Examples

football statistician c# task example 1

football statistician c# task example 2

asked in C# category by user eiorgert
edited by user golearnweb

1 Answer

+1 vote
 
Best answer

One of the most important things is to know how to remove empty spaces (SEE LINE 22)! This is the crucial for this task! The logic follows as usual but not everybody knows how to use String.Split Method (String[], StringSplitOptions) - Read more here: https://msdn.microsoft.com/en-us/library/tabh47cf%28v=vs.110%29.aspx

Anyhow, here is the solution for this great C# task :-)

using System;

class TheFootballStatistician
{
    static void Main()
    {
        decimal n = decimal.Parse(Console.ReadLine());

        int arsenalPoints = 0;
        int chelseaPoints = 0;
        int evertonPoints = 0;
        int liverpoolPoints = 0;
        int manchesterCityPoints = 0;
        int manchesterUnitedPoints = 0;
        int southamptonPoints = 0;
        int tottenhamPoints = 0;
        decimal payment = 0;

        string data = Console.ReadLine();
        while (data != "End of the league.")
        {
            string[] array = data.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            string firstTeam = array[0];
            string result = array[1];
            string secondTeam = array[2];

            int firstTeamPoints = 0;
            int secondTeamPoints = 0;

            if (result == "X")
            {
                firstTeamPoints += 1;
                secondTeamPoints += 1;
            }
            else if (result == "1")
            {
                firstTeamPoints += 3;
            }
            else if (result == "2")
            {
                secondTeamPoints += 3;
            }

            switch (firstTeam)
            {
                case "Arsenal": arsenalPoints += firstTeamPoints; break;
                case "Chelsea": chelseaPoints += firstTeamPoints; break;
                case "Everton": evertonPoints += firstTeamPoints; break;
                case "Liverpool": liverpoolPoints += firstTeamPoints; break;
                case "ManchesterCity": manchesterCityPoints += firstTeamPoints; break;
                case "ManchesterUnited": manchesterUnitedPoints += firstTeamPoints; break;
                case "Southampton": southamptonPoints += firstTeamPoints; break;
                case "Tottenham": tottenhamPoints += firstTeamPoints; break;
            }
            switch (secondTeam)
            {
                case "Arsenal": arsenalPoints += secondTeamPoints; break;
                case "Chelsea": chelseaPoints += secondTeamPoints; break;
                case "Everton": evertonPoints += secondTeamPoints; break;
                case "Liverpool": liverpoolPoints += secondTeamPoints; break;
                case "ManchesterCity": manchesterCityPoints += secondTeamPoints; break;
                case "ManchesterUnited": manchesterUnitedPoints += secondTeamPoints; break;
                case "Southampton": southamptonPoints += secondTeamPoints; break;
                case "Tottenham": tottenhamPoints += secondTeamPoints; break;
            }
            data = Console.ReadLine();
            for (int i = 0; i < array.Length; i++)
            {
                payment++;
            }
        }
        Console.WriteLine("{0:F2}lv.", payment * (n * 1.94m)/3);
        Console.WriteLine("Arsenal - {0} points.", arsenalPoints);
        Console.WriteLine("Chelsea - {0} points.", chelseaPoints);
        Console.WriteLine("Everton - {0} points.", evertonPoints);
        Console.WriteLine("Liverpool - {0} points.", liverpoolPoints);
        Console.WriteLine("Manchester City - {0} points.", manchesterCityPoints);
        Console.WriteLine("Manchester United - {0} points.", manchesterUnitedPoints);
        Console.WriteLine("Southampton - {0} points.", southamptonPoints);
        Console.WriteLine("Tottenham - {0} points.", tottenhamPoints);
    }
}

 

answered by user hues
selected by user golearnweb
...