deleriumbg

Untitled

Mar 17th, 2018
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.20 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Array_Manipulator
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             List<int> numbers = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
  12.             List<string> commands = Console.ReadLine().Split(' ').ToList();
  13.  
  14.             while (commands[0] != "print")
  15.             {
  16.                 if (commands[0] == "add")
  17.                 {
  18.                     numbers.Insert(int.Parse(commands[1]), int.Parse(commands[2]));
  19.                 }
  20.                 else if (commands[0] == "addMany")
  21.                 {
  22.                     numbers.InsertRange(int.Parse(commands[1]), commands.Skip(2).Select(int.Parse));
  23.                 }
  24.                 else if (commands[0] == "contains")
  25.                 {
  26.                     if (numbers.Contains(int.Parse(commands[1])))
  27.                     {
  28.                         Console.WriteLine(numbers.IndexOf(int.Parse(commands[1])));
  29.                     }
  30.                     else
  31.                     {
  32.                         Console.WriteLine("-1");
  33.                     }
  34.                 }
  35.                 else if (commands[0] == "remove")
  36.                 {
  37.                     numbers.RemoveAt(int.Parse(commands[1]));
  38.                 }
  39.                 else if (commands[0] == "shift")
  40.                 {
  41.                     int shifts = int.Parse(commands[1]);
  42.                     List<int> temp = numbers.Skip(shifts).ToList();
  43.                     for (int i = 0; i < shifts; i++)
  44.                     {
  45.                         temp.Add(numbers[i]);
  46.                     }
  47.                     numbers = temp;
  48.                 }
  49.                 else if (commands[0] == "sumPairs")
  50.                 {
  51.                     int cycles = numbers.Count / 2;
  52.                     for (int i = 0; i < cycles; i++)
  53.                     {
  54.                         numbers[i] += numbers[i + 1];
  55.                         numbers.RemoveAt(i + 1);
  56.                     }
  57.                 }
  58.                 commands = Console.ReadLine().Split(' ').ToList();
  59.             }
  60.             Console.WriteLine($"[ {string.Join(", ", numbers)} ]");
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment