Advertisement
DAtanasova

Upgraded Matcher

Jun 12th, 2017
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. class Program
  4. {
  5. static void Main()
  6. {
  7. string[] products = Console.ReadLine().Split(' ');
  8. long[] quantityInput = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
  9. decimal[] prices = Console.ReadLine().Split(' ').Select(decimal.Parse).ToArray();
  10.  
  11. long[] quantity = new long[products.Length];
  12. for (int i = 0; i < quantityInput.Length; i++)
  13. {
  14. quantity[i] = quantityInput[i];
  15. }
  16. while (true)
  17. {
  18. string[] element = Console.ReadLine().Split(' ');
  19. if (element[0] == "done")
  20. {
  21. break;
  22. }
  23. long neededQuantity = long.Parse(element[1]);
  24. int indexElement = Array.IndexOf(products, element[0]);
  25. if (neededQuantity <= quantity[indexElement])
  26. {
  27. decimal totalPrice = neededQuantity * prices[indexElement];
  28. Console.WriteLine($"{products[indexElement]} x {neededQuantity} costs {Math.Round(totalPrice, 2)}");
  29. quantity[indexElement] = quantity[indexElement] - neededQuantity;
  30. }
  31. else
  32. {
  33. Console.WriteLine($"We do not have enough {products[indexElement]}");
  34. }
  35. }
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement