Guest User

Array Manipulator - last judge test fail

a guest
Apr 10th, 2017
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.45 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. public class ArrayManipulator
  6. {
  7.     public static void Main()
  8.     {
  9.         List<int> inputList = Console.ReadLine()
  10.             .Split(new char[] { ' ' }, StringSplitOptions
  11.             .RemoveEmptyEntries)
  12.             .Select(int.Parse)
  13.             .ToList();
  14.  
  15.         while (true)
  16.         {
  17.             List<string> inputCommands = Console.ReadLine()
  18.             .Split(new char[] { ' ' }, StringSplitOptions
  19.             .RemoveEmptyEntries)
  20.             .ToList();
  21.  
  22.             string command = inputCommands[0];
  23.  
  24.             List<int> parameters = new List<int>();
  25.             for (int i = 1; i < inputCommands.Count; i++)
  26.             {
  27.                 parameters.Add(int.Parse(inputCommands[i]));
  28.             }
  29.  
  30.  
  31.             if (command == "print")
  32.             {
  33.                 break;
  34.             }
  35.  
  36.             switch (command)
  37.             {
  38.                 case "add":
  39.                     inputList.Insert(parameters[0], parameters[1]);
  40.                     break;
  41.  
  42.                 case "addMany":
  43.                     GC.Collect();
  44.                     int position = parameters[0];
  45.                     parameters.RemoveAt(0);
  46.                     inputList.InsertRange(position, parameters);
  47.                     break;
  48.  
  49.                 case "contains":
  50.                     Console.WriteLine(inputList.IndexOf(parameters[0]));
  51.                     break;
  52.  
  53.                 case "remove":
  54.                     inputList.RemoveAt(parameters[0]);
  55.                     break;
  56.  
  57.                 case "shift":
  58.                     GC.Collect();
  59.                     int shiftAmmount = parameters[0] % inputList.Count;
  60.                     for (int i = 0; i < shiftAmmount; i++)
  61.                     {
  62.                         int temp = inputList[0];
  63.                         inputList.RemoveAt(0);
  64.                         inputList.Add(temp);
  65.                     }
  66.                     break;
  67.  
  68.                 case "sumPairs":
  69.                     GC.Collect();
  70.                     for (int i = 0; i < inputList.Count-1; i++)
  71.                     {
  72.                         inputList[i] = inputList[i] + inputList[i + 1];
  73.                         inputList.RemoveAt(i + 1);
  74.                     }
  75.                     break;
  76.  
  77.                 default:
  78.                     break;
  79.             }
  80.         }
  81.  
  82.         Console.WriteLine($"[{ string.Join(", ", inputList)}]");
  83.     }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment