Lists - Exercises / 05. Array Manipulator
Test #11 (Runtime error)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _05.Array_Manipulator
{
class Program
{
static void Main(string[] args)
{
List<int> list = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
while (true)
{
List<string> command = Console.ReadLine().Split(' ').ToList();
switch (command[0])
{
case "print":
Console.WriteLine("["+String.Join(", ",list)+"]");
return;
case "add":
int index = int.Parse(command[1]);
int element = int.Parse(command[2]);
list.Insert(index,element);
break;
case "addMany":
for (int i = 0; i < command.Count-2; i++)
{
list.Insert(int.Parse(command[1]) + i, int.Parse(command[i + 2]));
}
break;
case "contains":
Console.WriteLine(list.IndexOf(int.Parse(command[1])));
break;
case "remove":
list.RemoveAt(int.Parse(command[1]));
break;
case "shift":
int position = int.Parse(command[1]);
for (int i = 0; i < position; i++)
{
list.Add(list[0]);
list.RemoveAt(0);
}
break;
case "sumPairs":
for (int i = 0; i < list.Count; i++)
{
int currSum = list[i]+list[i+1];
list.RemoveAt(i+1);
list.RemoveAt(i);
list.Insert(i,currSum);
}
break;
}
}
}
}
}