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

Q: Problem solving in C# Task - Torrent Pirate

+4 votes

Captain Jack Sparrow is a famous pirate. He loves to steal different stuff just for fun and he loves watching movies. He recently discovered a brand new technology called peer-to-peer or torrent. After he browsed a famous site, he made a collection of movies he would like to download. Assume 1 movie has a size of 1500MB. Jack doesn’t want to pay for the internet, so he decided to go to the mall and use the free Wi-Fi there. The Wi-Fi has a fixed speed of 2MB/s. Unfortunately for Jack, his wife will be going with him to the mall and this means that the download would not be free at all. She likes to buy sandals and other useless stuff. You are given the money his wife spends per hour at the mall.

Your task is to help Jack calculate whether it is cheaper to go to the mall and download the movies or go to the cinema to watch them. If the amount is the same, Jack still wants to make his wife happy, so he goes to the mall.

Input:

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

  • Download data d: how much megabytes in total Jack should download.
  • Price of cinema p: how much money would cost Jack to go to the cinema to watch one movie.
  • Wife spending  w: how much money per hour does Jack’s wife spend.

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 “{place to go} -> {price to pay}lv”.
  • The price to pay should be formatted with 2 digits after the decimal sign.

Constraints:

  • d is an integer number in range [0...2,147,483,647]. p is an integer number in range [0…30]. w is an integer number in range [0…200].
  • Allowed working time for your program: 0.25 seconds.
  • Allowed memory: 16 MB.

Examples:

Input

Output

Comments

30000

5

50

cinema -> 100.00lv

Download time =

= (download data)/(fixed speed)/(seconds)/(minutes) =

= 30000 / 2 / 60 / 60 = 4.1667 hours in the mall

Price for download = (download time)*(wife spending) =

= 4.1667*50 = 208.34lv

Number of movies downloaded =

= (download data)/(movie size) = 30000/1500 = 20 movies

Cinema price =

= (number of movies)*(cinema price) = 20*5lv = 100lv

Result on the console: cinema -> 100lv

Input

Output

Input

Output

30000

15

50

mall -> 208.33lv

30000

15

72

mall -> 300.00lv

 

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

1 Answer

+2 votes
 
Best answer

Here is my solution:

 

using System;

class TorrentPirate
{
    static void Main()
    {
        //Download time = (download data)/(fixed speed)/(seconds)/(minutes) =
        //= 30000 / 2 / 60 / 60 = 4.1667 hours in the mall

        //Price for download = (download time)*(wife spending) =
        //= 4.1667*50 = 208.34lv

        //Number of movies downloaded =
        //= (download data)/(movie size) = 30000/1500 = 20 movies

        //Cinema price =
        //= (number of movies)*(cinema price) = 20*5lv = 100lv
        //Result on the console: cinema -> 100lv

        double d = double.Parse(Console.ReadLine());//30000 Download data d: how much megabytes in total Jack should download.
        double p = double.Parse(Console.ReadLine());//5 Price of cinema p: how much money would cost Jack to go to the cinema to watch one movie.
        double w = double.Parse(Console.ReadLine());//50 Wife spending w: how much money per hour does Jack’s wife spend.

        double downloadTime = (d / 2 / 60 / 60);
        double priceForDownload = (downloadTime * w);
        double numberOfMoviesDownloaded = (d / 1500);

        double cinemaPrice = (numberOfMoviesDownloaded * p);
        double mallPrice = (downloadTime * w);

        if (cinemaPrice < mallPrice)
        {
            Console.WriteLine("cinema -> {0:F2}lv", cinemaPrice);
        }
        else
        {
            Console.WriteLine("mall -> {0:F2}lv", mallPrice);
        }

    }
}

 

answered by user ak47seo
edited by user golearnweb
Be careful with the numerical data type = otherwise you will have incorrect output!
...