GerganaTsirkova

ArrayManipulator

Feb 11th, 2018
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.41 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace ManipulateArray
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             List<string> arr = Console.ReadLine().Split(' ').ToList();
  12.             int n = int.Parse(Console.ReadLine());
  13.  
  14.             for (int i = 0; i < n; i++)
  15.             {
  16.                 string[] command = Console.ReadLine().Split(' ').ToArray();
  17.                 if (command[0]== "Reverse")
  18.                 {
  19.                     arr.Reverse();
  20.                 }
  21.                 else if(command[0] == "Distinct")
  22.                 {
  23.                     arr=arr.Distinct().ToList();
  24.                 }
  25.                 else if (command[0] == "Replace")
  26.                 {
  27.                     int index = int.Parse(command[1]);
  28.                     arr.Insert(index,command[2]);
  29.                     arr.RemoveAt(index + 1);
  30.                 }
  31.                 else
  32.                 {
  33.                     i--;
  34.                     continue;
  35.                 }
  36.                 if(i==n-1)
  37.                 {
  38.                     if(arr.Count==0)
  39.                     {
  40.                         Console.WriteLine();
  41.                     }
  42.                     else
  43.                     {
  44.                         Console.WriteLine(string.Join(", ", arr));
  45.                     }
  46.                 }
  47.             }
  48.            
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment