Advertisement
miroLLL

BeerStock

Jan 26th, 2016
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.37 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 _02.Problem_BeerStock
  8. {
  9.     class BeerStock
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             uint reservedBeers = uint.Parse(Console.ReadLine());
  14.             string inputData = Console.ReadLine();
  15.             uint allBeers = 0;
  16.  
  17.             while (inputData != "Exam Over")
  18.             {
  19.                 string[] inputDataSplit = inputData.Split(' ');
  20.                 uint numBeers = uint.Parse(inputDataSplit[0]);
  21.  
  22.                 if (inputDataSplit[1] == "beers")
  23.                 {
  24.                     allBeers += numBeers;
  25.                 }
  26.                 else if (inputDataSplit[1] == "cases")          
  27.                 {
  28.                     uint calcBeersInCases =  numBeers * 24;
  29.                     allBeers += calcBeersInCases;
  30.                 }
  31.                 else if (inputDataSplit[1] == "sixpacks")
  32.                 {
  33.                     uint calcBeersInSixpacks = numBeers * 6;
  34.                     allBeers += calcBeersInSixpacks;
  35.                 }
  36.                
  37.                 inputData = Console.ReadLine();
  38.             }
  39.  
  40.             if (allBeers >= 100)
  41.             {
  42.                 allBeers = allBeers - (allBeers / 100);
  43.             }
  44.  
  45.             if (allBeers >= reservedBeers)
  46.             {
  47.                 uint beersLeft = allBeers - reservedBeers;
  48.  
  49.                 uint leftCases = beersLeft / 24;
  50.                 uint beersLeftFromCases = beersLeft - (leftCases * 24);
  51.  
  52.                 uint leftSixpacks = beersLeftFromCases / 6;
  53.                 uint leftBeers = beersLeftFromCases - (leftSixpacks * 6);
  54.  
  55.                 Console.WriteLine("Cheers! Beer left: {0} cases, {1} sixpacks and {2} beers.", leftCases, leftSixpacks, leftBeers);
  56.             }
  57.  
  58.             else
  59.             {
  60.                 uint notEnought = reservedBeers - allBeers;
  61.  
  62.                 uint needCases = notEnought / 24;
  63.                 uint beersLeftFromCases = notEnought - (needCases * 24);
  64.  
  65.                 uint needSixpacs = beersLeftFromCases / 6;
  66.                 uint needBeer = beersLeftFromCases - (needSixpacs * 6);
  67.  
  68.                 Console.WriteLine("Not enough beer. Beer needed: {0} cases, {1} sixpacks and {2} beers.", needCases, needSixpacs, needBeer);              
  69.             }
  70.         }
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement