Advertisement
baxlash

Master Herbalist

Jan 26th, 2016
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.55 KB | None | 0 0
  1. using System;
  2.  
  3. class MasterHerbalist
  4. {
  5.     static void Main(string[] args)
  6.     {
  7.         string currentInput = string.Empty;
  8.         int dailyExpenses = int.Parse(Console.ReadLine());
  9.         double balance = 0;
  10.         int days = 0;
  11.  
  12.         while (true)
  13.         {
  14.             int hours = 0;
  15.             int dailyHerbs = 0;
  16.             int dailyPrice = 0;
  17.             currentInput = Console.ReadLine();
  18.             if (currentInput == "Season Over")
  19.             {
  20.                 break;
  21.             }
  22.  
  23.             string[] splited = currentInput.Split(' ');
  24.             hours = int.Parse(splited[0]);
  25.             dailyPrice = int.Parse(splited[2]);
  26.             string path = splited[1];
  27.  
  28.             for (int i = 0; i < hours; i++)
  29.             {
  30.                 int index = i;
  31.                 if (index > path.Length - 1)
  32.                 {
  33.                     index %= path.Length;
  34.                 }
  35.  
  36.                 if (path[index] == 'H')
  37.                 {
  38.                     dailyHerbs++;
  39.                 }
  40.             }
  41.             int dailyIncome = dailyPrice * dailyHerbs;
  42.             int dailyBalance = dailyIncome - dailyExpenses;
  43.             balance += dailyBalance;
  44.             days++;
  45.         }
  46.         if (balance > 0)
  47.         {
  48.             double avarageBalance = balance / days;
  49.             Console.WriteLine("Times are good. Extra money per day: {0:F2}.", avarageBalance);
  50.         }
  51.         else
  52.         {
  53.             Console.WriteLine("We are in the red. Money needed: {0}.", balance * (-1));
  54.         }
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement