Advertisement
Guest User

Untitled

a guest
Jun 13th, 2017
342
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.25 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace SimpleProblems
  5. {
  6.     class Program
  7.     {
  8.         public static int maxIndex;
  9.         static void Main(string[] args)
  10.         {
  11.             string[] elm = Console.ReadLine().Split(' ').ToArray();
  12.             maxIndex = elm.Length;
  13.             int n = int.Parse(Console.ReadLine());
  14.             for (int i = 0; i < n; i++)
  15.             {
  16.                 string command = Console.ReadLine();
  17.  
  18.                 switch (command)
  19.                 {
  20.                     case "Reverse":
  21.                         elm = Reverse(elm,maxIndex);
  22.                         break;
  23.                     case "Distinct":
  24.                         elm = Distinct(elm,maxIndex);
  25.                         break;
  26.                     default:
  27.                         string[] replace = command.Split(' ').ToArray();
  28.                         elm[int.Parse(replace[1])] = replace[2];
  29.                         break;
  30.                 }
  31.             }
  32.             Print(elm,maxIndex);
  33.  
  34.         }
  35.         static string[] Reverse(string[] arr, int maxInd)
  36.         {
  37.             string[] reversed = new string[maxInd];
  38.             int index = 0;
  39.             for (int i = maxInd - 1; i >= 0; i--)
  40.             {
  41.                 reversed[index] = arr[i];
  42.                 index++;
  43.             }
  44.             return reversed;
  45.         }
  46.         static string[] Distinct(string[] arr, int maxInd)
  47.         {
  48.             string[] distincted = new string[maxInd];
  49.             int index = 0;
  50.             for (int i = 0; i < maxInd; i++)
  51.             {
  52.                 string curr = arr[i];
  53.                 if (curr == "0") continue;
  54.                 for (int j = 0; j < maxInd; j++)
  55.                 {
  56.                     if (arr[j] == curr)
  57.                     {
  58.                         arr[j] = "0";
  59.                     }
  60.                 }
  61.                 distincted[index] = curr;
  62.                 index++;
  63.             }
  64.             maxIndex = index;
  65.             return distincted;
  66.         }
  67.         static void Print(string[] arr, int maxInd)
  68.         {
  69.             for (int i = 0; i < maxInd - 1; i++)
  70.             {
  71.                 Console.Write(arr[i] + ", ");
  72.             }
  73.             Console.WriteLine(arr[maxInd - 1]);
  74.         }
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement