[해결로 표시] Impress the girlfriend - C# Task

  

4
주제 스타터

Spiro is a big CS GO fan. He's been saving money for months to buy the new Counter Strike game. However, he has five options to buy the game from.

The first one is a shady Russian site selling games in rubles (Russian currency). Another option is an American site selling games in dollars (American currency). Spiro's third option is the official site of the game - selling games in euros (European Union currency). The final 2 options are Bulgarian sites B and M. Both of them sell in leva (Bulgarian currency).

B offers a very special deal - 2 copies of the game for the price of one. M sells games for normal prices. Spiro is very bad with math and can't calculate the game prices in leva. But he wants to impress his girlfriend by showing her he bought the most expensive game.

Assume that Spiro has a girlfriend, all games are identical, 100 rubles are 3.5 leva, 1 dollar is 1.5 leva, 1 euro is 1.95 leva

and if Spiro buys 2 special games from B and he always sell one of them for exactly half of the money he paid for both.

Your task is to write a program that calculates the most expensive game.

Input

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

  • The number r – amount of rubles Spiro has to pay for the game at the Russian site.
  • The number d – amount of dollars Spiro has to pay for the game at the American site.
  • The number e – amount of euro Spiro has to pay for the game at the official site.
  • The number b – amount of leva Spiro has to pay for the special offer at B.
  • The number m – amount of leva Spiro has to pay for the game at M's site.

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 most expensive game price rounded up to the next integer number.

Constraints

  • The numbers r, d, e, b, m are integer numbers in range [0... 4,294,967,295].
  • Allowed working time for your program: 0.1 seconds.
  • Allowed memory: 16 MB.

Examples

impress the girlfriend c sharp task example1

impress the girlfriend c sharp task example 2

impress the girlfriend c sharp task example 3

impress the girlfriend c sharp task example 4

2개 답글
3

Here's my solution to your task:

using System;
 
class ImpressTheGirlfriend
{
    static void Main()
    {
        decimal rubles = decimal.Parse(Console.ReadLine());
        decimal dollars = decimal.Parse(Console.ReadLine());
        decimal euro = decimal.Parse(Console.ReadLine());
        decimal bgOne = decimal.Parse(Console.ReadLine());
        decimal bgTwo = decimal.Parse(Console.ReadLine());
         
        decimal rublesLv = rubles * 0.035m;
        decimal dollarsLv = dollars * 1.5m;
        decimal euroLv = euro * 1.95m;
        decimal bgOneConv = bgOne / 2;
 
        if (rublesLv > dollarsLv && rublesLv > euroLv && rublesLv > bgOneConv && rublesLv > bgTwo)
        {
            Console.WriteLine("{0:F2}", Math.Ceiling(rublesLv));
        }
 
        else if (dollarsLv > rublesLv && dollarsLv > euroLv && dollarsLv > bgOneConv && dollarsLv > bgTwo)
        {
            Console.WriteLine("{0:F2}", Math.Ceiling(dollarsLv));
        }
 
        else if (euroLv > rublesLv && euroLv > dollarsLv && euroLv > bgOneConv && euroLv > bgTwo)
        {
            Console.WriteLine("{0:F2}", Math.Ceiling(euroLv));
        }
 
        else if (bgOneConv > rublesLv && bgOneConv > dollarsLv && bgOneConv > euroLv && bgOneConv > bgTwo)
        {
            Console.WriteLine("{0:F2}", Math.Ceiling(bgOneConv));
        }
 
        else if (bgTwo > rublesLv && bgTwo > dollarsLv && bgTwo > euroLv && bgTwo > bgOneConv)
        {
            Console.WriteLine("{0:F2}", Math.Ceiling(bgTwo));
        }
    }
}
1

The same solution like eiorgert's one - but at the end with array (using array's method array.Max();) - it is more evelegant one - without ifs + again with Math.Ceiling and the placeholder {0:f2}:

using System;
using System.Linq;
 
class ImpressTheGirlfriend
{
    static void Main()
    {
        decimal rubles = decimal.Parse(Console.ReadLine());
        decimal dollars = decimal.Parse(Console.ReadLine());
        decimal euro = decimal.Parse(Console.ReadLine());
        decimal bgOne = decimal.Parse(Console.ReadLine());
        decimal bgTwo = decimal.Parse(Console.ReadLine());
 
        decimal rublesLv = rubles * 0.035m;
        decimal dollarsLv = dollars * 1.5m;
        decimal euroLv = euro * 1.95m;
        decimal bgOneConv = bgOne / 2;
 
        decimal[] array = new[] { rublesLv, dollarsLv, euroLv, bgOneConv, bgTwo };
 
        Console.WriteLine("{0:f2}", Math.Ceiling(array.Max()));
    }
}
공유: