Advertisement
Guest User

Untitled

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