Advertisement
Katina_

The Final Quest

Jun 29th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.56 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace TheFinalQuest
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             List<string> realMessage = Console.ReadLine().Split(" ").ToList();
  12.  
  13.             while (true)
  14.             {
  15.                 string[] commands = Console.ReadLine().Split(" ");
  16.  
  17.                 string command = commands[0];
  18.  
  19.                 if (command == "Stop")
  20.                 {
  21.                     break;
  22.                 }
  23.  
  24.                 if (command == "Swap")
  25.                 {
  26.                     string firstWord = commands[1];
  27.                     string secondWord = commands[2];
  28.  
  29.                     if (realMessage.Contains(firstWord) && realMessage.Contains(secondWord))
  30.                     {
  31.                         int firstWordIndex = realMessage.IndexOf(firstWord);
  32.                         int secondWordIndex = realMessage.IndexOf(secondWord);
  33.  
  34.                         realMessage[firstWordIndex] = secondWord;
  35.                         realMessage[secondWordIndex] = firstWord;
  36.                     }
  37.                 }
  38.  
  39.                 if (command == "Put")
  40.                 {
  41.                     string word = commands[1];
  42.                     int index = int.Parse(commands[2]) - 1;
  43.  
  44.                     if (index >= 0 && index <= realMessage.Count)
  45.                     {
  46.                         realMessage.Insert(index, word);
  47.                     }
  48.                 }
  49.  
  50.                 if (command == "Sort")
  51.                 {
  52.                     realMessage.Sort();
  53.                     realMessage.Reverse();
  54.  
  55.                     // realMessage = realMessage.OrderByDescending(x => x).ToList();
  56.                 }
  57.  
  58.                 if (command == "Replace")
  59.                 {
  60.                     string firstWord = commands[1];
  61.                     string secondWord = commands[2];
  62.  
  63.                     if (realMessage.Contains(secondWord))
  64.                     {
  65.                         int secondWordIndex = realMessage.IndexOf(secondWord);
  66.  
  67.                         realMessage[secondWordIndex] = firstWord;
  68.                     }
  69.                 }
  70.  
  71.                 if (command == "Delete")
  72.                 {
  73.                     int index = int.Parse(commands[1]) + 1;
  74.                     if (index >= 0 && index < realMessage.Count)
  75.                     {
  76.                         realMessage.RemoveAt(index);
  77.                     }
  78.                 }
  79.             }
  80.  
  81.             Console.WriteLine(string.Join(" ", realMessage));
  82.         }
  83.     }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement