Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- public class Program
- {
- public static void Main()
- {
- List<int> numbers = Console.ReadLine().Split(' ').Select(n => int.Parse(n)).ToList();
- while (true)
- {
- String command = Console.ReadLine();
- if (command == "print")
- {
- break;
- }
- String[] cmd = command.Split(' ');
- if (cmd[0] == "push")
- {
- numbers.Add(int.Parse(cmd[1]));
- }
- else if (cmd[0] == "pop")
- {
- Console.WriteLine(numbers[numbers.Count - 1]);
- numbers.RemoveAt(numbers.Count - 1);
- }
- else if (cmd[0] == "shift")
- {
- int first = numbers[0];
- int last = numbers[numbers.Count - 1];
- numbers.RemoveAt(0);
- numbers.RemoveAt(numbers.Count - 1);
- numbers.Add(first);
- numbers.Insert(0, last);
- }
- else if (cmd[0] == "remove")
- {
- int index = int.Parse(cmd[1]);
- if (numbers.Count > index)
- {
- numbers.RemoveAt(index);
- }
- }
- else if (cmd[0] == "addMany")
- {
- int index = int.Parse(cmd[1]);
- if (numbers.Count > index)
- {
- for (int i = 2; i < cmd.Length; i++)
- {
- numbers.Insert(index, int.Parse(cmd[i]));
- index++;
- }
- }
- }
- }
- numbers.Reverse();
- Console.WriteLine(string.Join(",", numbers));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement