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();
- int counter = 0;
- while (true)
- {
- counter++;
- if (counter > 1000)
- {
- GC.Collect();
- counter = 0;
- }
- List<string> inputCommands = Console.ReadLine()
- .Split(new char[] { ' ' }, StringSplitOptions
- .RemoveEmptyEntries)
- .ToList();
- 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 (command == "print")
- {
- break;
- }
- switch (command)
- {
- case "add":
- inputList.Insert(parameters[0], parameters[1]);
- break;
- case "addMany":
- int position = parameters[0];
- parameters.RemoveAt(0);
- inputList.InsertRange(position, parameters);
- break;
- case "contains":
- Console.WriteLine(inputList.IndexOf(parameters[0]));
- break;
- case "remove":
- inputList.RemoveAt(parameters[0]);
- break;
- case "shift":
- int shiftAmmount = parameters[0] % inputList.Count;
- for (int i = 0; i < shiftAmmount; i++)
- {
- int temp = inputList[0];
- inputList.RemoveAt(0);
- inputList.Add(temp);
- }
- break;
- case "sumPairs":
- 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