Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace MasterHerbalist
- {
- class Program
- {
- public static void Main(string[] args)
- {
- int penkasDailyExpences = int.Parse(Console.ReadLine());
- string infoInput = string.Empty;
- int letterCount = 0;
- int forCount = 0;
- int hCount = 0;
- int counterForHerbs = 0;
- int moneyPerDay = 0;
- int totalMoneyMade = 0;
- int counterForDays = 0;
- double averageMoneyPerDay = 0;
- double extraOrNeededMoney = 0;
- while (true)
- {
- infoInput = Console.ReadLine();
- if (infoInput != "Season Over")
- {
- string[] hourHebsAndPrice = infoInput.Split(' ');
- counterForDays++;
- //get the hours
- int hours;
- bool parseHours = int.TryParse(hourHebsAndPrice[0], out hours);
- //get the herbs --> "H"
- letterCount = 0;
- forCount = 0;
- hCount = 0;
- counterForHerbs = hours;
- while (hours > 0)
- {
- if (letterCount == hourHebsAndPrice[1].Length)
- {
- forCount++;
- letterCount = -1;
- hours -= hourHebsAndPrice[1].Length;
- }
- letterCount++;
- }
- for (int currentRotate = 0; currentRotate < forCount; currentRotate++)
- {
- for (int currentLetter = 0; currentLetter < hourHebsAndPrice[1].Length; currentLetter++)
- {
- char letter = (hourHebsAndPrice[1])[currentLetter];
- if (currentLetter == counterForHerbs)
- {
- break;
- }
- if (letter == 'H')
- {
- hCount++;
- }
- }
- counterForHerbs -= hourHebsAndPrice[1].Length;
- }
- //get the price of the gathered herbs
- int priceForAHerb;
- bool priceParce = int.TryParse(hourHebsAndPrice[2], out priceForAHerb);
- moneyPerDay = (hCount * priceForAHerb);
- totalMoneyMade += moneyPerDay;
- //null the values
- letterCount = 0;
- forCount = 0;
- hCount = 0;
- counterForHerbs = 0;
- moneyPerDay = 0;
- }
- else
- {
- break;
- }
- }
- averageMoneyPerDay = ((double)totalMoneyMade / (double)counterForDays);
- extraOrNeededMoney = Math.Abs(averageMoneyPerDay - (double)penkasDailyExpences);
- if (penkasDailyExpences <= averageMoneyPerDay)
- {
- extraOrNeededMoney = (averageMoneyPerDay - (double)penkasDailyExpences);
- Console.WriteLine("Times are good. Extra money per day: {0:f2}.", extraOrNeededMoney);
- }
- else
- {
- extraOrNeededMoney = Math.Abs(totalMoneyMade - penkasDailyExpences * counterForDays);
- Console.WriteLine("We are in the red. Money needed: {0}.", Math.Truncate(extraOrNeededMoney));
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement