Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace CottageScrapper
- {
- class Program
- {
- static void Main(string[] args)
- {
- string input = Console.ReadLine();
- var Trees = new Dictionary<string, List<double>>();
- var Used = new List<double>();
- var unUsed = new List<double>();
- while (input != "chop chop")
- {
- string[] inputTokens = input
- .Split(new string[] { " -> " }, StringSplitOptions.RemoveEmptyEntries);
- //Count++;
- if (!Trees.ContainsKey(inputTokens[0]))
- {
- Trees.Add(inputTokens[0], new List<double>());
- }
- Trees[inputTokens[0]].Add(double.Parse(inputTokens[1]));
- input = Console.ReadLine();
- }
- string NeededType = Console.ReadLine();
- double NeededHeight = double.Parse(Console.ReadLine());
- //foreach (var log in Trees)
- //{
- // if (log.Key == NeededType)
- // {
- // for (int i = 0; i < log.Value.Count; i++)
- // {
- // if (log.Value[i] >= NeededHeight)
- // {
- // Used.Add(log.Value[i]);
- // }
- // else
- // {
- // unUsed.Add(log.Value[i]);
- // }
- // }
- // }
- // else
- // {
- // unUsed.AddRange(log.Value);
- // }
- //}
- /*понеже задачите са от ламда и линку ти предлагам следното решение*/
- double count = Trees.Values.Sum(x => x.Count);
- double pplm = Math.Round(Trees.Values.Sum(x => x.Sum()) / count, 2);
- var used = Math.Round(Trees[NeededType].Where(x => x >= NeededHeight).Sum() * pplm, 2);
- var unused = Math.Round((Trees.Values.Sum(x => x.Sum())
- - Trees[NeededType].Where(x => x >= NeededHeight).Sum()) * pplm * 0.25, 2);
- Console.WriteLine("Price per meter: ${0:0.00}", pplm);
- Console.WriteLine("Used logs price: ${0:0.00}", used);
- Console.WriteLine("Unused logs price: ${0:0.00}", unused);
- Console.WriteLine("CottageScraper subtotal: ${0:0.00}", used + unused);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement