Advertisement
Guest User

Untitled

a guest
Jul 19th, 2017
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.55 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace CottageScrapper
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             string input = Console.ReadLine();
  12.             var Trees = new Dictionary<string, List<double>>();
  13.             var Used = new List<double>();
  14.             var unUsed = new List<double>();
  15.             while (input != "chop chop")
  16.             {
  17.                 string[] inputTokens = input
  18.                     .Split(new string[] { " -> " }, StringSplitOptions.RemoveEmptyEntries);
  19.                 //Count++;
  20.                 if (!Trees.ContainsKey(inputTokens[0]))
  21.                 {
  22.                     Trees.Add(inputTokens[0], new List<double>());
  23.                 }
  24.                 Trees[inputTokens[0]].Add(double.Parse(inputTokens[1]));
  25.                 input = Console.ReadLine();
  26.  
  27.             }
  28.  
  29.             string NeededType = Console.ReadLine();
  30.             double NeededHeight = double.Parse(Console.ReadLine());
  31.             //foreach (var log in Trees)
  32.             //{
  33.             //    if (log.Key == NeededType)
  34.             //    {
  35.             //        for (int i = 0; i < log.Value.Count; i++)
  36.             //        {
  37.             //            if (log.Value[i] >= NeededHeight)
  38.             //            {
  39.             //                Used.Add(log.Value[i]);
  40.             //            }
  41.             //            else
  42.             //            {
  43.             //                unUsed.Add(log.Value[i]);
  44.             //            }
  45.             //        }
  46.             //    }
  47.             //    else
  48.             //    {
  49.             //        unUsed.AddRange(log.Value);
  50.             //    }
  51.             //}
  52.  
  53.             /*понеже задачите са от ламда и линку ти предлагам следното решение*/
  54.             double count = Trees.Values.Sum(x => x.Count);
  55.             double pplm = Math.Round(Trees.Values.Sum(x => x.Sum()) / count, 2);
  56.  
  57.             var used = Math.Round(Trees[NeededType].Where(x => x >= NeededHeight).Sum() * pplm, 2);
  58.  
  59.             var unused = Math.Round((Trees.Values.Sum(x => x.Sum())
  60.                 - Trees[NeededType].Where(x => x >= NeededHeight).Sum()) * pplm * 0.25, 2);
  61.  
  62.             Console.WriteLine("Price per meter: ${0:0.00}", pplm);
  63.             Console.WriteLine("Used logs price: ${0:0.00}", used);
  64.             Console.WriteLine("Unused logs price: ${0:0.00}", unused);
  65.             Console.WriteLine("CottageScraper subtotal: ${0:0.00}", used + unused);
  66.         }
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement