Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- public class ArrayManipulator
- {
- public static void Main()
- {
- List<int> inputList = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToList();
- while (true)
- {
- string[] inputCommands = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
- //string command = inputCommands[0];
- //List<int> parameters = new List<int>();
- //for (int i = 1; i < inputCommands.Count; i++)
- //{
- // parameters.Add(int.Parse(inputCommands[i]));
- //}
- if (inputCommands[0] == "print")
- {
- break;
- }
- switch (inputCommands[0])
- {
- case "add":
- inputList.Insert(int.Parse(inputCommands[1]), int.Parse(inputCommands[2]));
- break;
- case "addMany":
- //GC.Collect();
- //int position = int.Parse(inputCommands[0]);
- //inputCommands = inputCommands.Skip(2).ToArray();
- inputList.InsertRange(int.Parse(inputCommands[1]), inputCommands.Skip(2).Select(int.Parse));
- break;
- case "contains":
- Console.WriteLine(inputList.IndexOf(int.Parse(inputCommands[1])));
- break;
- case "remove":
- inputList.RemoveAt(int.Parse(inputCommands[1]));
- break;
- case "shift":
- //GC.Collect();
- int shiftAmmount = int.Parse(inputCommands[1]) % inputList.Count;
- for (int i = 0; i < shiftAmmount; i++)
- {
- int temp = inputList[0];
- inputList.RemoveAt(0);
- inputList.Add(temp);
- }
- break;
- case "sumPairs":
- //GC.Collect();
- for (int i = 0; i < inputList.Count - 1; i++)
- {
- inputList[i] = inputList[i] + inputList[i + 1];
- inputList.RemoveAt(i + 1);
- }
- break;
- default:
- break;
- }
- }
- Console.WriteLine($"[{ string.Join(", ", inputList)}]");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment