Advertisement
Terziyski

Manipulate Array

Jun 15th, 2017
385
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.20 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Problem_2.Manipulate_Array
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string[] arr = Console.ReadLine().Split(' ').ToArray();
  14.             int lines = int.Parse(Console.ReadLine());
  15.  
  16.  
  17.             var changeArray = arr;
  18.            
  19.  
  20.             for (int i = 0; i < lines; i++)
  21.             {
  22.                 string commands = Console.ReadLine();
  23.  
  24.                 if (commands == "Distinct")
  25.                 {
  26.                     changeArray = changeArray.Distinct().ToArray();
  27.                 }
  28.                 if (commands == "Reverse")
  29.                 {
  30.                     Array.Reverse(changeArray);
  31.                    
  32.                 }
  33.                 if (commands != "Distinct" && commands != "Reverse")
  34.                 {
  35.                     string[] replace = commands.Split(' ').ToArray();
  36.                     changeArray[int.Parse(replace[1])] = replace[2];
  37.                    
  38.                 }
  39.             }
  40.             Console.WriteLine(string.Join(", ", changeArray));
  41.            
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement