Advertisement
didatzi

P08_UpgradedMatcher

Jun 15th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.69 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 P08_UpgradedMatcher
  8. {
  9.     class P08_UpgradedMatcher
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string[] products = Console.ReadLine().Split();
  14.             long[] quantitiesOfProducts = Console.ReadLine().Split().Select(long.Parse).ToArray();
  15.             decimal[] priceOfProducts = Console.ReadLine().Split().Select(decimal.Parse).ToArray();
  16.             long[] allQuantities = new long[products.Length];
  17.  
  18.             for (int i = 0; i < quantitiesOfProducts.Length; i++)
  19.             {
  20.                 allQuantities[i] = quantitiesOfProducts[i];
  21.             }
  22.             while (true)
  23.             {
  24.                 string[] command = Console.ReadLine().Split();
  25.                 string product = command[0];
  26.  
  27.                 if (product == "done")
  28.                 {
  29.                     break;
  30.                 }
  31.  
  32.                 long usedQuantity = long.Parse(command[1]);
  33.                 int indexProduct = Array.IndexOf(products, product);
  34.  
  35.                 if (allQuantities[indexProduct] == 0 || usedQuantity > allQuantities[indexProduct])
  36.                 {
  37.                     Console.WriteLine($"We do not have enough {product}");
  38.                 }
  39.                 if (usedQuantity <= allQuantities[indexProduct])
  40.                 {
  41.                     decimal totalPrice = usedQuantity * priceOfProducts[indexProduct];
  42.                     Console.WriteLine($"{product} x {usedQuantity} costs {totalPrice:F2}");
  43.                     allQuantities[indexProduct] -= usedQuantity;
  44.                 }
  45.             }
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement