Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace SimpleProblems
- {
- class Program
- {
- public static int maxIndex;
- static void Main(string[] args)
- {
- string[] elm = Console.ReadLine().Split(' ').ToArray();
- maxIndex = elm.Length;
- int n = int.Parse(Console.ReadLine());
- for (int i = 0; i < n; i++)
- {
- string command = Console.ReadLine();
- switch (command)
- {
- case "Reverse":
- elm = Reverse(elm,maxIndex);
- break;
- case "Distinct":
- elm = Distinct(elm,maxIndex);
- break;
- default:
- string[] replace = command.Split(' ').ToArray();
- elm[int.Parse(replace[1])] = replace[2];
- break;
- }
- }
- Print(elm,maxIndex);
- }
- static string[] Reverse(string[] arr, int maxInd)
- {
- string[] reversed = new string[maxInd];
- int index = 0;
- for (int i = maxInd - 1; i >= 0; i--)
- {
- reversed[index] = arr[i];
- index++;
- }
- return reversed;
- }
- static string[] Distinct(string[] arr, int maxInd)
- {
- string[] distincted = new string[maxInd];
- int index = 0;
- for (int i = 0; i < maxInd; i++)
- {
- string curr = arr[i];
- if (curr == "0") continue;
- for (int j = 0; j < maxInd; j++)
- {
- if (arr[j] == curr)
- {
- arr[j] = "0";
- }
- }
- distincted[index] = curr;
- index++;
- }
- maxIndex = index;
- return distincted;
- }
- static void Print(string[] arr, int maxInd)
- {
- for (int i = 0; i < maxInd - 1; i++)
- {
- Console.Write(arr[i] + ", ");
- }
- Console.WriteLine(arr[maxInd - 1]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement