Advertisement
angelneychev

05.Coins

Oct 11th, 2018
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.53 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _05.Coins
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             decimal input = decimal.Parse(Console.ReadLine());
  14.  
  15.             long leva = (long)input;
  16.             long twoLeva = leva / 2;
  17.             long oneLeva = leva % 2;
  18.             decimal coinsCounter = twoLeva + oneLeva;
  19.             decimal cent = (input * 100) % 100;
  20.             while (cent > 0)
  21.             {
  22.                 if (cent >= 50)
  23.                 {
  24.                     cent -= 50;
  25.                     coinsCounter++;
  26.                 }
  27.                 else if (cent < 50 && cent >= 20)
  28.                 {
  29.                     cent -= 20;
  30.                     coinsCounter++;
  31.                 }
  32.                 else if (cent < 20 && cent >= 10)
  33.                 {
  34.                     cent -= 10;
  35.                     coinsCounter++;
  36.                 }
  37.                 else if (cent < 10 && cent >= 5)
  38.                 {
  39.                     cent -= 5;
  40.                     coinsCounter++;
  41.                 }
  42.                 else if (cent < 5 && cent >= 2)
  43.                 {
  44.                     cent -= 2;
  45.                     coinsCounter++;
  46.                 }
  47.                 else if (cent < 2 && cent >= 1)
  48.                 {
  49.                     cent -= 10;
  50.                     coinsCounter++;
  51.                 }
  52.  
  53.             }
  54.             Console.WriteLine(coinsCounter);
  55.         }
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement