NadyaMisheva

fynkcii

Mar 16th, 2019
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. public class Program
  5. {
  6. public static void Main()
  7. {
  8. List<int> numbers = Console.ReadLine().Split(' ').Select(n => int.Parse(n)).ToList();
  9. while(true)
  10. {
  11. string command = Console.ReadLine();
  12. if(command == "print")
  13. {
  14. numbers.Reverse();
  15. break;
  16. }
  17. string[] cmd = command.Split(' ');
  18. if(cmd[0] == "push")
  19. {
  20. numbers.Add(int.Parse(cmd[1]));
  21. }
  22. else if(cmd[0] == "pop")
  23. {
  24. Console.WriteLine(numbers[numbers.Count - 1]);
  25. numbers.RemoveAt(numbers.Count - 1);
  26. }
  27. else if(cmd[0] == "shift")
  28. {
  29. int first = numbers[0];
  30. int last = numbers[numbers.Count - 1];
  31. numbers.RemoveAt(0);
  32. numbers.RemoveAt(numbers.Count - 1);
  33. numbers.Add(first);
  34. numbers.Insert(0, last);
  35. }
  36. else if(cmd[0] == "remove")
  37. {
  38. int index = int.Parse(cmd[1]);
  39. if(numbers.Count - 1 < index )
  40. {
  41. numbers.RemoveAt(index);
  42. }
  43. }
  44. else if(cmd[0] == "addMany")
  45. {
  46. int index1 = int.Parse(cmd[1]);
  47. for(int i = 2; i < cmd.Length; i++)
  48. {
  49. numbers.Insert(index1, int.Parse(cmd[i]));
  50. index1++;
  51. }
  52. }
  53. }
  54. Console.WriteLine(string.Join(", ", numbers));
  55. }
  56. }
Add Comment
Please, Sign In to add comment