Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Created by SharpDevelop.
- * User: savina.ivancheva
- * Date: 18.08.2017
- * Time: 09:18
- *
- * To change this template use Tools | Options | Coding | Edit Standard Headers.
- */
- using System;
- using System.Linq;
- namespace SafeManipulation
- {
- class Program
- {
- public static void Main(string[] args)
- {
- var input = Console.ReadLine().Split(' ');
- var manipulatedArray = input;
- int lengthArr = manipulatedArray.Length;
- string[] command = Console.ReadLine().Split(' ');
- while (command[0] != "END")
- {
- string action = command[0];
- if (action == "Reverse")
- {
- manipulatedArray = manipulatedArray.Reverse().ToArray();
- }
- else if (action == "Distinct")
- {
- manipulatedArray = manipulatedArray.Distinct().ToArray();
- lengthArr = manipulatedArray.Count(s => s != null);
- }
- else if (action == "Replace")
- {
- int index = int.Parse(command[1]);
- string wordToChange = command[2];
- if (index > lengthArr-1 || (index < 0))
- {
- Console.WriteLine("Invalid input!");
- }
- else
- {
- manipulatedArray[index] = wordToChange;
- }
- }
- else
- {
- Console.WriteLine("Invalid input!");
- }
- command = Console.ReadLine().Split(' ').ToArray();
- }
- Console.WriteLine(String.Join(", ", manipulatedArray));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement