Aliendreamer

cottagescrapper

Jul 17th, 2017
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.36 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _06LinqExcercisesCottageScrapper
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.  
  14.             Dictionary<string, List<int>> logs = new Dictionary<string,List<int>>();
  15.  
  16.             string input = Console.ReadLine();
  17.  
  18.  
  19.             while(input!="chop chop")
  20.             {
  21.  
  22.                 string[] inputTokens = input.Split(new string[] { " -> " }, StringSplitOptions.RemoveEmptyEntries).ToArray();
  23.  
  24.                 string typeOfThree = inputTokens[0];
  25.                 int height = int.Parse(inputTokens[1]);
  26.  
  27.                 if (!logs.ContainsKey(typeOfThree))
  28.                 {
  29.                     logs.Add(typeOfThree ,new List<int>());
  30.                 }
  31.                 logs[typeOfThree].Add(height);
  32.  
  33.  
  34.  
  35.                 input = Console.ReadLine();
  36.             }
  37.             string desiredTree = Console.ReadLine();
  38.             int desiredHeight = int.Parse(Console.ReadLine());
  39.             // input done
  40.             // Console.WriteLine("half way done input taken in!");
  41.  
  42.             int totalLogLength = 0;
  43.             int count = 0;
  44.             foreach (List<int> item in logs.Values)
  45.             {
  46.                 for(int i=0;i<item.Count;i++)
  47.                 {
  48.                     totalLogLength += item[i];
  49.                     count++;
  50.                 }
  51.  
  52.             }
  53.  
  54.             decimal logPrice = Math.Round((decimal)totalLogLength / count,2);
  55.  
  56.             List<int> usedLogs = logs[desiredTree]
  57.                 .ToList()
  58.                 .Where(item => item >=desiredHeight)
  59.                 .ToList();
  60.  
  61.             int usedmaterials = usedLogs.Sum();
  62.  
  63.             int unusedmaterials = totalLogLength - usedmaterials;
  64.  
  65.             decimal usedLogsPrice =Math.Round(usedmaterials * logPrice,2);
  66.             decimal unusedLogsPrice = Math.Round((unusedmaterials * logPrice) * 0.25M, 2);
  67.             decimal total = Math.Round(usedLogsPrice + unusedLogsPrice, 2);
  68.            
  69.             Console.WriteLine("Price per meter: ${0}",logPrice);
  70.             Console.WriteLine("Used logs price: ${0}",usedLogsPrice);
  71.             Console.WriteLine("Unused logs price: ${0}",unusedLogsPrice);
  72.             Console.WriteLine("CottageScraper subtotal: ${0}",total);
  73.  
  74.         }
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment