settingsAccountsettings
By using our mini forum, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy
Menusettings

Q: Traveller Bob - Travelling By Plane - C# Task

+4 votes

Bob loves travelling by plane. Thankfully, his job of being a businessman involves traveling a couple of times during the month. Bob is a busy man. He has months when he uses his private jet in order to go and sign new contracts. In a contract month, he travels 3 times per week. Although Bob loves his work, he also cares about his family. He spends family months, when he has 1 less travel per week than a contract month and he travels only 2 weeks. The other months are considered "normal" during which Bob travels 2/5 less than during contract months.

In addition, if the year is leap, Bob travels 5% more overall. Assume that a month has exactly 4 weeks.

Your task is to write a program that calculates how many times Bob travels around the world during the year (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 c – number of months Bob signs contracts in the year.
  • The number f – number of months that Bob spends with his family.

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 the number of travels as integer.

Constraints

  • The numbers c is in range [0...12] and f is in range [0…12].
  • Allowed working time for your program: 0.25 seconds.
  • Allowed memory: 16 MB.

Examples:

traveller Bob task

Traveller Bob C sharp task screenshot 2

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

1 Answer

+1 vote
 
Best answer

Interesting C# task :-) A bit foggy in the description (need to be careful with weeks, months and years - not to mention - the family time), but otherwise cool :-)

Here is my solution:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class TravellerBob
{
    static void Main()
    {
        string yearType = Console.ReadLine();
        decimal contractsMonths = decimal.Parse(Console.ReadLine());//per month = 12
        decimal familyMonths = decimal.Parse(Console.ReadLine());//per month = 4

        decimal contractFlights = contractsMonths * 12;
        decimal familyFlights = familyMonths * 4;
        decimal normalFlights = ((12 - (contractsMonths + familyMonths)) * 12) * 0.6m;//0.6 - because 3/5 = 0.6 (5/5-2/5=3/5)

        decimal yearLeapFlights = (contractFlights + familyFlights + normalFlights) + ((contractFlights + familyFlights + normalFlights) * 0.05m);
        decimal yearNormalFlights = contractFlights + familyFlights + normalFlights;

        switch (yearType)
        {
            case "leap":
                Console.WriteLine(Math.Floor(yearLeapFlights));
                break;
            case "normal":
                Console.WriteLine(Math.Floor(yearNormalFlights));
                break;
        }
    }
}
answered by user mitko
selected by user golearnweb
...