Advertisement
Guest User

Problem 8. * Upgraded Matcher

a guest
May 12th, 2018
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace ConsoleApp5
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10.  
  11. string[] products = Console.ReadLine().Split(' ').ToArray();
  12. ulong[] availability = Console.ReadLine().Split(' ').Select(ulong.Parse).ToArray();
  13. decimal[] prices = Console.ReadLine().Split(' ').Select(decimal.Parse).ToArray();
  14.  
  15. int index = 0;
  16.  
  17. while (true)
  18. {
  19. string[] product = Console.ReadLine().Split(' ').ToArray();
  20.  
  21. if (product[0] == "done")
  22. {
  23. break;
  24. }
  25.  
  26. index = Array.IndexOf(products, product[0]);
  27.  
  28. try
  29. {
  30. if (ulong.Parse(product[1]) <= availability[index])
  31. {
  32. Console.WriteLine($"{product[0]} x {product[1]} costs {ulong.Parse(product[1]) * prices[index]}");
  33. availability[index] -= ulong.Parse(product[1]);
  34.  
  35. }
  36. else
  37. {
  38. Console.WriteLine($"We do not have enough {product[0]}");
  39. }
  40. }
  41. catch (Exception)
  42. {
  43. Console.WriteLine($"We do not have enough {product[0]}");
  44. }
  45. }
  46. }
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement