Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- class CottageScraper
- {
- static void Main()
- {
- var productsAndPrices = new Dictionary<string, List<int>>();
- var logsCount = 0;
- var typeLog = string.Empty;
- while (true)
- {
- var inputLine = Console.ReadLine();
- if (inputLine == "chop chop")
- {
- inputLine = Console.ReadLine();
- typeLog = inputLine;
- inputLine = Console.ReadLine();
- logsCount = int.Parse(inputLine);
- break;
- }
- var tokens = inputLine.Split(' ');
- var log = tokens[0];
- var count = int.Parse(tokens[2]);
- if (! productsAndPrices.ContainsKey(log))
- {
- productsAndPrices[log] = new List<int>();
- }
- productsAndPrices[log].Add(count);
- }
- decimal usedLogs = 0;
- decimal unusedLogs = 0;
- decimal allLogs = 0;
- foreach (var kvp in productsAndPrices)
- {
- if (kvp.Key == typeLog)
- {
- foreach (var count in kvp.Value)
- {
- if (count > logsCount)
- {
- usedLogs += count;
- allLogs++;
- }
- else
- {
- unusedLogs += count;
- allLogs++;
- }
- }
- }
- }
- foreach (var kvp in productsAndPrices)
- {
- if (kvp.Key != typeLog)
- {
- foreach (var count in kvp.Value)
- {
- unusedLogs += count;
- allLogs++;
- }
- }
- }
- decimal pricePerMeter = Math.Round(((decimal)usedLogs + unusedLogs) / allLogs, 2);
- decimal usedLogsPrice = Math.Round(usedLogs * pricePerMeter, 2);
- decimal unusedLogsPrice = Math.Round((unusedLogs * pricePerMeter) * 0.25m, 2);
- decimal subtotal = Math.Round(usedLogsPrice + unusedLogsPrice, 2);
- Console.WriteLine($"Price per meter: ${pricePerMeter}");
- Console.WriteLine($"Used logs price: ${usedLogsPrice}");
- Console.WriteLine($"Unused logs price: ${unusedLogsPrice}");
- Console.WriteLine($"CottageScraper subtotal: ${subtotal}");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment