Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Problem_2.Manipulate_Array
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[] arr = Console.ReadLine().Split(' ').ToArray();
- var changeArray = arr;
- var count = 0;
- while (true)
- {
- string commands = Console.ReadLine();
- for (int i = 0; i < arr.Length - 1 ; i++)
- {
- if (arr[i] == arr[i + 1])
- {
- count++;
- }
- }
- if (commands == "Distinct")
- {
- if (count > 0)
- {
- changeArray = changeArray.Distinct().ToArray();
- }
- else
- {
- Console.WriteLine("Invalid input!");
- }
- }
- if (commands == "Reverse")
- {
- Array.Reverse(changeArray);
- }
- if (commands != "Distinct" && commands != "Reverse" && commands != "END")
- {
- string[] replace = commands.Split(' ').ToArray();
- int temp = int.Parse(replace[1]);
- if (temp >= changeArray.Length || temp < 0 )
- {
- Console.WriteLine("Invalid input!");
- continue;
- }
- changeArray[int.Parse(replace[1])] = replace[2];
- }
- if (commands == "END")
- {
- break;
- }
- }
- Console.WriteLine(string.Join(", ", changeArray));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement