Advertisement
petarkobakov

Froggy Squad

Jul 3rd, 2020
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.05 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Froggy_Squad
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. List<string> froggies = Console.ReadLine().Split().ToList();
  12. string command = Console.ReadLine();
  13.  
  14. while (!(command.Contains("Print")))
  15. {
  16. string[] elements = command.Split();
  17. string operation = elements[0];
  18.  
  19. if (operation == "Join")
  20. {
  21.  
  22. string name = elements[1];
  23. froggies.Add(name);
  24. }
  25. else if (operation == "Jump")
  26. {
  27.  
  28. string name = elements[1];
  29. int index = int.Parse(elements[2]);
  30.  
  31. if (index >= 0 && index < froggies.Count)
  32. {
  33. froggies.Insert(index, name);
  34. }
  35. }
  36. else if (operation == "Dive")
  37. {
  38.  
  39. int index = int.Parse(elements[1]);
  40.  
  41. if (index >= 0 && index < froggies.Count)
  42. {
  43.  
  44. froggies.Remove(froggies[index]);
  45. }
  46. }
  47. else if (operation == "First")
  48. {
  49.  
  50. int count = int.Parse(elements[1]);
  51. if (count>=froggies.Count)
  52. {
  53. Console.WriteLine(string.Join(' ',froggies));
  54. }
  55. else
  56. {
  57. for (int i = 0; i < count; i++)
  58. {
  59. Console.Write(froggies[i] + " ");
  60. }
  61. Console.WriteLine();
  62. }
  63. }
  64. else if (operation == "Last")
  65. {
  66.  
  67. int count = int.Parse(elements[1]);
  68. if (count>=froggies.Count)
  69. {
  70. Console.WriteLine(string.Join(' ', froggies));
  71. }
  72. else
  73. {
  74. for (int i = froggies.Count-count; i < froggies.Count; i++)
  75. {
  76. Console.Write(froggies[i] + " ");
  77. }
  78. Console.WriteLine();
  79. }
  80.  
  81. }
  82.  
  83. command = Console.ReadLine();
  84. }
  85.  
  86. string[] element = command.Split();
  87. if (element[1] == "Reversed")
  88. {
  89. froggies.Reverse();
  90. Console.Write($"Frogs: {string.Join(' ', froggies)}");
  91. }
  92. else
  93. {
  94. Console.Write($"Frogs: {string.Join(' ', froggies)}");
  95. }
  96. }
  97.  
  98. }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement