Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace ConsoleApp1
  5. {
  6. class Program
  7. {
  8. static void Main()
  9. {
  10. var gifts = Console.ReadLine().Split(" ").ToList();
  11. string input = string.Empty;
  12.  
  13. while ((input = Console.ReadLine()) != "No Money")
  14. {
  15.  
  16. var splitedInput = input.Split(" ").ToList();
  17.  
  18. if (splitedInput[0] == "OutOfStock")
  19. {
  20. if (splitedInput.Count() == 2)
  21. {
  22. for (int i = 0; i < gifts.Count; i++)
  23. {
  24. if (gifts[i].Contains(splitedInput[1]))
  25. {
  26. int index = gifts.IndexOf(splitedInput[1]);
  27. string outOfStockGift = splitedInput[1];
  28. gifts.Remove(splitedInput[1]);
  29. gifts.Insert(index, "None");
  30. }
  31. }
  32. }
  33. }
  34. else if (splitedInput[0] == "Required")
  35. {
  36. if (splitedInput.Count == 3)
  37. {
  38. string gift = splitedInput[1];
  39. int index = int.Parse(splitedInput[2]);
  40.  
  41. if (index >= 0 && index < gifts.Count)
  42. {
  43. gifts.RemoveAt(index);
  44. gifts.Insert(index, gift);
  45. }
  46. }
  47. }
  48. else if (splitedInput[0] == "JustInCase")
  49. {
  50. if (splitedInput.Count() == 2)
  51. {
  52. int lastIndex = gifts.Count - 1;
  53. gifts.RemoveAt(lastIndex);
  54. gifts.Add(splitedInput[1]);
  55. }
  56. }
  57. }
  58. if (gifts.Contains("None"))
  59. {
  60. gifts.RemoveAll(gift => gift == "None");
  61. }
  62. Console.WriteLine(string.Join(" ", gifts));
  63. }
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement