fbinnzhivko

Count Beers

Mar 11th, 2016
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.65 KB | None | 0 0
  1. using System;
  2. class Program
  3. {
  4.     static void Main()
  5.     {
  6.  
  7.         string line = Console.ReadLine();
  8.  
  9.         int beerCount = 0;
  10.  
  11.         while (line != "End")
  12.         {
  13.             string[] data = line.Split(' ');
  14.             int count = int.Parse(data[0]);
  15.             string type = data[1];
  16.             if (type == "beers") { beerCount += count; }
  17.             else if (type == "stacks") { beerCount += count * 20; }
  18.  
  19.             line = Console.ReadLine();
  20.         }
  21.         int totalStacks = beerCount / 20;
  22.         int leftBeers = beerCount % 20;
  23.  
  24.  
  25.         Console.WriteLine("{0} stacks + {1} beers", totalStacks, leftBeers);
  26.  
  27.  
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment