Advertisement
Guest User

08_UpgradedMatcher

a guest
Jun 16th, 2017
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.81 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 _08_UpgradedMatcher
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             var productNames = Console.ReadLine().Split(' ').ToArray();
  14.             var productQuantity = Console.ReadLine().Split(' ').Select(long.Parse).ToList();
  15.             decimal[] productPrice = Console.ReadLine().Split(' ').Select(decimal.Parse).ToArray();
  16.  
  17.  
  18.             var diff = productNames.Length - productQuantity.Count;
  19.             for (int i = 0; i < diff; i++)
  20.             {
  21.                 productQuantity.Add(0);
  22.             }
  23.  
  24.  
  25.             long quantityNeeded = 0;
  26.  
  27.             while (true)
  28.             {
  29.                 var product = Console.ReadLine().Split(' ').ToArray();
  30.  
  31.  
  32.  
  33.                 if (product[0] == "done")
  34.                 {
  35.  
  36.                     return;
  37.                 }
  38.  
  39.                 quantityNeeded = long.Parse(product[1]);
  40.  
  41.                 for (int i = 0; i < productNames.Length; i++)
  42.                 {
  43.                     if (product[0].Equals(productNames[i]))
  44.                     {
  45.                         productQuantity[i] -= quantityNeeded;
  46.                         if (productQuantity[i] >= 0)
  47.                         {
  48.                             var totalPrice = quantityNeeded * productPrice[i];
  49.  
  50.                             Console.WriteLine($"{productNames[i]} x {quantityNeeded} costs {totalPrice:F2} ");
  51.                         }
  52.                         else
  53.                         {
  54.                             Console.WriteLine($"We do not have enough {productNames[i]}");
  55.                             productQuantity[i] += quantityNeeded;
  56.                         }
  57.                     }
  58.                 }
  59.             }
  60.         }
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement