Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _06LinqExcercisesCottageScrapper
- {
- class Program
- {
- static void Main(string[] args)
- {
- Dictionary<string, List<int>> logs = new Dictionary<string,List<int>>();
- string input = Console.ReadLine();
- while(input!="chop chop")
- {
- string[] inputTokens = input.Split(new string[] { " -> " }, StringSplitOptions.RemoveEmptyEntries).ToArray();
- string typeOfThree = inputTokens[0];
- int height = int.Parse(inputTokens[1]);
- if (!logs.ContainsKey(typeOfThree))
- {
- logs.Add(typeOfThree ,new List<int>());
- }
- logs[typeOfThree].Add(height);
- input = Console.ReadLine();
- }
- string desiredTree = Console.ReadLine();
- int desiredHeight = int.Parse(Console.ReadLine());
- // input done
- // Console.WriteLine("half way done input taken in!");
- int totalLogLength = 0;
- int count = 0;
- foreach (List<int> item in logs.Values)
- {
- for(int i=0;i<item.Count;i++)
- {
- totalLogLength += item[i];
- count++;
- }
- }
- decimal logPrice = Math.Round((decimal)totalLogLength / count,2);
- List<int> usedLogs = logs[desiredTree]
- .ToList()
- .Where(item => item >=desiredHeight)
- .ToList();
- int usedmaterials = usedLogs.Sum();
- int unusedmaterials = totalLogLength - usedmaterials;
- decimal usedLogsPrice =Math.Round(usedmaterials * logPrice,2);
- decimal unusedLogsPrice = Math.Round((unusedmaterials * logPrice) * 0.25M, 2);
- decimal total = Math.Round(usedLogsPrice + unusedLogsPrice, 2);
- Console.WriteLine("Price per meter: ${0}",logPrice);
- Console.WriteLine("Used logs price: ${0}",usedLogsPrice);
- Console.WriteLine("Unused logs price: ${0}",unusedLogsPrice);
- Console.WriteLine("CottageScraper subtotal: ${0}",total);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment