Advertisement
simonradev

Master Herbalist

Oct 21st, 2016
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.63 KB | None | 0 0
  1. using System;
  2.  
  3. namespace MasterHerbalist
  4. {
  5.     class Program
  6.     {
  7.         public static void Main(string[] args)
  8.         {
  9.             int penkasDailyExpences = int.Parse(Console.ReadLine());
  10.             string infoInput = string.Empty;
  11.             int letterCount = 0;
  12.             int forCount = 0;
  13.             int hCount = 0;
  14.             int counterForHerbs = 0;
  15.             int moneyPerDay = 0;
  16.             int totalMoneyMade = 0;
  17.             int counterForDays = 0;
  18.             double averageMoneyPerDay = 0;
  19.             double extraOrNeededMoney = 0;
  20.            
  21.             while (true)
  22.             {
  23.                 infoInput = Console.ReadLine();
  24.                
  25.                 if (infoInput != "Season Over")
  26.                 {
  27.                     string[] hourHebsAndPrice = infoInput.Split(' ');
  28.                     counterForDays++;
  29.                    
  30.                     //get the hours
  31.                     int hours;
  32.                     bool parseHours = int.TryParse(hourHebsAndPrice[0], out hours);
  33.                    
  34.                     //get the herbs --> "H"
  35.                     letterCount = 0;
  36.                     forCount = 0;
  37.                     hCount = 0;
  38.                     counterForHerbs = hours;
  39.            
  40.                     while (hours > 0)
  41.                     {
  42.                         if (letterCount == hourHebsAndPrice[1].Length)
  43.                         {
  44.                             forCount++;
  45.                             letterCount = -1;
  46.                             hours -= hourHebsAndPrice[1].Length;
  47.                         }
  48.                             letterCount++;
  49.                     }
  50.                    
  51.                     for (int currentRotate = 0; currentRotate < forCount; currentRotate++)
  52.                     {
  53.                         for (int currentLetter = 0; currentLetter < hourHebsAndPrice[1].Length; currentLetter++)
  54.                         {
  55.                             char letter = (hourHebsAndPrice[1])[currentLetter];
  56.                            
  57.                             if (currentLetter == counterForHerbs)
  58.                             {
  59.                                 break;
  60.                             }
  61.                             if (letter == 'H')
  62.                             {
  63.                                 hCount++;
  64.                             }
  65.                         }
  66.                         counterForHerbs -= hourHebsAndPrice[1].Length;
  67.                     }
  68.                    
  69.                     //get the price of the gathered herbs
  70.                     int priceForAHerb;
  71.                     bool priceParce = int.TryParse(hourHebsAndPrice[2], out priceForAHerb);
  72.                    
  73.                     moneyPerDay = (hCount * priceForAHerb);
  74.                     totalMoneyMade += moneyPerDay;
  75.                    
  76.                     //null the values
  77.                     letterCount = 0;
  78.                     forCount = 0;
  79.                     hCount = 0;
  80.                     counterForHerbs = 0;
  81.                     moneyPerDay = 0;
  82.                 }
  83.                 else
  84.                 {
  85.                     break;
  86.                 }
  87.             }
  88.            
  89.             averageMoneyPerDay = ((double)totalMoneyMade / (double)counterForDays);
  90.             extraOrNeededMoney = Math.Abs(averageMoneyPerDay - (double)penkasDailyExpences);
  91.            
  92.             if (penkasDailyExpences <= averageMoneyPerDay)
  93.             {
  94.                 extraOrNeededMoney = (averageMoneyPerDay - (double)penkasDailyExpences);
  95.                 Console.WriteLine("Times are good. Extra money per day: {0:f2}.", extraOrNeededMoney);
  96.             }
  97.             else
  98.             {
  99.                 extraOrNeededMoney = Math.Abs(totalMoneyMade - penkasDailyExpences * counterForDays);
  100.                 Console.WriteLine("We are in the red. Money needed: {0}.", Math.Truncate(extraOrNeededMoney));
  101.             }
  102.            
  103.         }
  104.     }
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement