settingsAccountsettings
Menusettings

Q: Problem solving in C# Task - Volleyball

+3 votes

Vladi loves a lot to play volleyball. However, he is a programmer now and he is very busy. Now he is able to play only in the holidays and in the weekends.

Vladi plays in 2/3 of the holidays and each Saturday, but not every weekend – only when he is not at work and only when he is not going to his hometown. Vladi goes at his hometown h weekends in the year. The other weekends are considered “normal”. Vladi is not at work in 3/4 of the normal weekends. When Vladi is at his hometown, he always plays volleyball with his old friends once, at Sunday. In addition, if the year is leap, Vladi plays volleyball 15% more times additionally. We assume the year has exactly 48 weekends suitable for volleyball.

Your task is to write a program that calculates how many times Vladi plays volleyball (rounded down to the nearest integer number).

Input

The input data should be read from the console. It consists of three input values, each at separate line:

  • The string “leap” for leap year or “normal” for year that is not leap.
  • The number p – number of holidays in the year (which are not Saturday or Sunday).
  • The number h – number of weekends that Vladi spends in his hometown.

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

Output

  • The output data must be printed on the console.
  • On the only output line you must print an integer representing how many times Vladi plays volleyball for a year.

Constraints

  • The numbers p is in range [0...300] and h is in range [0…48].
  • Allowed working time for your program: 0.25 seconds.
  • Allowed memory: 16 MB.

Examples

volleyball task in C# 1st screenshot

volleyball task in C# 2nd screenshot

volleyball task in C# 3rd screenshot

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

1 Answer

+1 vote
 
Best answer

However, here's my solution:

using System;

class Volleyball10April2014Evening
{
    static void Main()
    {
        string yearType = Console.ReadLine();//The string “leap” for leap year or “normal” for year that is not leap.
        int pHolidays = int.Parse(Console.ReadLine());//The number p – number of holidays in the year (which are not Saturday or Sunday).
        int hWeekendsInHome = int.Parse(Console.ReadLine());//The number h – number of weekends that Vladi spends in his hometown.

        int allWeekendsYear = 48;
        int normalWeekends = allWeekendsYear - hWeekendsInHome;
        double totalPlays = normalWeekends * 3.0/4;
        totalPlays += hWeekendsInHome;
        totalPlays += pHolidays*2.0/3;

        switch (yearType)
        {
            case "leap": totalPlays += totalPlays * 0.15;
                break;
            case "normal": totalPlays = totalPlays;
                break;
        }
        Console.WriteLine(Math.Floor(totalPlays));
    }
}

 

answered by user paulcabalit
edited by user golearnweb
...