Advertisement
igrilkul

Array manipulator

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