Guest User

Untitled

a guest
Jun 16th, 2017
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.54 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. class CottageScraper
  6. {
  7.     static void Main()
  8.     {
  9.         var productsAndPrices = new Dictionary<string, List<int>>();
  10.  
  11.         var logsCount = 0;
  12.         var typeLog = string.Empty;
  13.  
  14.         while (true)
  15.         {
  16.             var inputLine = Console.ReadLine();
  17.  
  18.             if (inputLine == "chop chop")
  19.             {
  20.                 inputLine = Console.ReadLine();
  21.                 typeLog = inputLine;
  22.  
  23.                 inputLine = Console.ReadLine();
  24.                 logsCount = int.Parse(inputLine);
  25.                 break;
  26.             }
  27.  
  28.             var tokens = inputLine.Split(' ');
  29.  
  30.             var log = tokens[0];
  31.             var count = int.Parse(tokens[2]);
  32.  
  33.             if (! productsAndPrices.ContainsKey(log))
  34.             {
  35.                 productsAndPrices[log] = new List<int>();
  36.             }
  37.  
  38.             productsAndPrices[log].Add(count);
  39.            
  40.         }
  41.  
  42.         decimal usedLogs = 0;
  43.         decimal unusedLogs = 0;
  44.         decimal allLogs = 0;
  45.  
  46.         foreach (var kvp in productsAndPrices)
  47.         {          
  48.             if (kvp.Key == typeLog)
  49.             {
  50.                 foreach (var count in kvp.Value)
  51.                 {
  52.                     if (count > logsCount)
  53.                     {
  54.                         usedLogs += count;
  55.                         allLogs++;
  56.                     }
  57.                     else
  58.                     {
  59.                         unusedLogs += count;
  60.                         allLogs++;
  61.                     }
  62.                 }
  63.             }
  64.         }
  65.  
  66.         foreach (var kvp in productsAndPrices)
  67.         {
  68.             if (kvp.Key != typeLog)
  69.             {
  70.                 foreach (var count in kvp.Value)
  71.                 {                  
  72.                     unusedLogs += count;
  73.                     allLogs++;
  74.                 }
  75.             }            
  76.         }
  77.  
  78.         decimal pricePerMeter = Math.Round(((decimal)usedLogs + unusedLogs) / allLogs, 2);
  79.         decimal usedLogsPrice = Math.Round(usedLogs * pricePerMeter, 2);
  80.         decimal unusedLogsPrice = Math.Round((unusedLogs * pricePerMeter) * 0.25m, 2);
  81.         decimal subtotal = Math.Round(usedLogsPrice + unusedLogsPrice, 2);
  82.  
  83.         Console.WriteLine($"Price per meter: ${pricePerMeter}");
  84.         Console.WriteLine($"Used logs price: ${usedLogsPrice}");
  85.         Console.WriteLine($"Unused logs price: ${unusedLogsPrice}");
  86.         Console.WriteLine($"CottageScraper subtotal: ${subtotal}");
  87.     }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment