Advertisement
Ronka

Untitled

Jun 11th, 2017
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 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 Arrays_MoreEx
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. string[] name = Console.ReadLine().Split(' '); // same
  14. long[] quantity = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
  15. decimal[] price = Console.ReadLine().Split(' ').Select(decimal.Parse).ToArray(); // same
  16.  
  17. while (true)
  18. {
  19. string inputName = Console.ReadLine();
  20. long inputQuantity = long.Parse(Console.ReadLine());
  21.  
  22. if (inputName == "done") // край на цикъла
  23. {
  24. break;
  25. }
  26.  
  27. int index = Array.IndexOf(name, inputName); //индекс на търсения елемент
  28. int quantityL = quantity.Length;
  29.  
  30. if (index >= quantityL) // ако няма индекса на дадения елемент в quantity,го приравняваме на 0
  31. {
  32. quantity = new long[quantityL + index];
  33. for (int i = 0; i < quantityL; i++)
  34. {
  35. quantity[quantityL - 1 + i] = 0;
  36. }
  37. }
  38.  
  39. // изчисляваме количеството
  40. if (quantity[index] >= inputQuantity)
  41. {
  42. decimal totalPrice = (decimal) price[index] * inputQuantity;
  43. quantity[index] -= inputQuantity;
  44. Console.WriteLine($"{inputQuantity} x {inputName} costs {totalPrice:F2}");
  45. }
  46. else
  47. {
  48. Console.WriteLine($"We do not have enough {inputName}");
  49. }
  50.  
  51.  
  52. }
  53.  
  54. }
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement