Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace P08_UpgradedMatcher
- {
- class P08_UpgradedMatcher
- {
- static void Main(string[] args)
- {
- string[] products = Console.ReadLine().Split();
- long[] quantitiesOfProducts = Console.ReadLine().Split().Select(long.Parse).ToArray();
- decimal[] priceOfProducts = Console.ReadLine().Split().Select(decimal.Parse).ToArray();
- long[] allQuantities = new long[products.Length];
- for (int i = 0; i < quantitiesOfProducts.Length; i++)
- {
- allQuantities[i] = quantitiesOfProducts[i];
- }
- while (true)
- {
- string[] command = Console.ReadLine().Split();
- string product = command[0];
- if (product == "done")
- {
- break;
- }
- long usedQuantity = long.Parse(command[1]);
- int indexProduct = Array.IndexOf(products, product);
- if (allQuantities[indexProduct] == 0 || usedQuantity > allQuantities[indexProduct])
- {
- Console.WriteLine($"We do not have enough {product}");
- }
- if (usedQuantity <= allQuantities[indexProduct])
- {
- decimal totalPrice = usedQuantity * priceOfProducts[indexProduct];
- Console.WriteLine($"{product} x {usedQuantity} costs {totalPrice:F2}");
- allQuantities[indexProduct] -= usedQuantity;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement