Created
February 16, 2016 21:12
-
-
Save Kiso-blg/2153b447979414c1ef0d to your computer and use it in GitHub Desktop.
02.BeerStock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace Problem_2___Beer_Stock | |
{ | |
class BeerStock | |
{ | |
static void Main(string[] args) | |
{ | |
long reservedBeers = long.Parse(Console.ReadLine()); | |
long beers = 0; | |
long sixPacks = 0; | |
long cases = 0; | |
while (true) | |
{ | |
string purchase = Console.ReadLine(); | |
if (purchase == "Exam Over") | |
{ | |
break; | |
} | |
else | |
{ | |
string[] amountAndType = purchase.Split(' '); | |
if (amountAndType[1] == "beers") | |
{ | |
beers += long.Parse(amountAndType[0]); | |
} | |
else if (amountAndType[1] == "sixpacks") | |
{ | |
sixPacks += 6 * long.Parse(amountAndType[0]); | |
} | |
else if (amountAndType[1] == "cases") | |
{ | |
cases += 24 * long.Parse(amountAndType[0]); | |
} | |
} | |
} | |
long wholeAmount = beers + sixPacks + cases; | |
if (wholeAmount >= 100) | |
{ | |
wholeAmount = wholeAmount - (wholeAmount / 100); | |
} | |
if (wholeAmount >= reservedBeers) | |
{ | |
long leftBeers = wholeAmount - reservedBeers; | |
long leftCases = leftBeers / 24; | |
long leftSixPacks = (leftBeers - leftCases * 24) / 6; | |
long leftBotles = leftBeers - (leftCases * 24) - (leftSixPacks * 6); | |
Console.WriteLine("Cheers! Beer left: {0} cases, {1} sixpacks and {2} beers.", | |
leftCases, leftSixPacks, leftBotles); | |
} | |
else | |
{ | |
long insufficientBeers = reservedBeers - wholeAmount; | |
long insufficientCases = insufficientBeers / 24; | |
long insufficientSixPacks = (insufficientBeers - insufficientCases * 24) / 6; | |
long insufficientBottles = insufficientBeers - (insufficientCases * 24) - (insufficientSixPacks * 6); | |
Console.WriteLine("Not enough beer. Beer needed: {0} cases, {1} sixpacks and {2} beers.", | |
insufficientCases, insufficientSixPacks, insufficientBottles); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment