Advertisement
Spocoman

Beer Stock

Oct 11th, 2023
666
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.36 KB | None | 0 0
  1. using System;
  2.  
  3. namespace BeerStock
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int neededBeers = int.Parse(Console.ReadLine());
  10.             long deliveredBeers = 0;
  11.             string command;
  12.  
  13.             while ((command = Console.ReadLine()) != "Exam Over")
  14.             {
  15.                 var package = command.Split(' ');
  16.                 long amount = long.Parse(package[0]);
  17.                 string type = package[1];
  18.  
  19.                 if (type == "sixpacks")
  20.                 {
  21.                     amount *= 6;
  22.                 }
  23.                 else if (type == "cases")
  24.                 {
  25.                     amount *= 24;
  26.                 }
  27.                 deliveredBeers += amount;
  28.             }
  29.  
  30.             deliveredBeers -= deliveredBeers / 100;
  31.             long diff = Math.Abs(neededBeers - deliveredBeers);
  32.             long cases = diff / 24;
  33.             long sixpacks = diff % 24 / 6;
  34.             long beers = diff % 6;
  35.  
  36.             if (deliveredBeers >= neededBeers)
  37.             {
  38.                 Console.WriteLine($"Cheers! Beer left: {cases} cases, {sixpacks} sixpacks and {beers} beers.");
  39.             }
  40.             else
  41.             {
  42.                 Console.WriteLine($"Not enough beer. Beer needed: {cases} cases, {sixpacks} sixpacks and {beers} beers.");
  43.             }
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement