Guest User

03. The Final Quest

a guest
Jun 26th, 2019
197
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Numerics;
  5.  
  6. class Program
  7. {
  8.     public static List<string> words = new List<string>();
  9.     static void Main()
  10.     {
  11.         words = Console.ReadLine().Split(" ").ToList();
  12.  
  13.         string input;
  14.  
  15.         while ((input = Console.ReadLine()) != "Stop")
  16.         {
  17.             string[] commands = input.Split(" ");
  18.             string command = commands[0];
  19.            
  20.             int index;
  21.             string word, word1, word2;
  22.  
  23.             switch (command)
  24.             {
  25.                 case "Delete":
  26.                     index = int.Parse(commands[1]);
  27.                     Delete(index);
  28.                     break;
  29.                 case "Swap":
  30.                     word1 = commands[1];
  31.                     word2 = commands[2];
  32.                     Swap(word1, word2);
  33.                     break;
  34.                 case "Put":
  35.                     word = commands[1];
  36.                     index = int.Parse(commands[2]);
  37.                     Put(word, index);
  38.                     break;
  39.                 case "Sort":
  40.                     words.Sort();
  41.                     words.Reverse();
  42.                     break;
  43.                 case "Replace":
  44.                     word1 = commands[1];
  45.                     word2 = commands[2];
  46.                     Replace(word1, word2);
  47.                     break;
  48.  
  49.                 default:
  50.                     break;
  51.             }
  52.  
  53.         }
  54.  
  55.         words.ForEach(w => Console.Write(w + " "));
  56.         return;
  57.     }
  58.     public static void Delete(int index)
  59.     {
  60.         if (words.Count > index + 1 && index + 1 > -1)
  61.         {
  62.             words.RemoveAt(index + 1);
  63.         }
  64.         return;
  65.     }
  66.     public static void Swap(string word1, string word2)
  67.     {
  68.         if (words.Contains(word1) && words.Contains(word2))
  69.         {
  70.             int index1 = words.IndexOf(word1);
  71.             int index2 = words.IndexOf(word2);
  72.  
  73.             words[index2] = word1;
  74.             words[index1] = word2;
  75.         }
  76.         return;
  77.     }
  78.     public static void Put(string word, int index)
  79.     {
  80.         if (/*words.Count > index - 1 && index - 1 > -1*/ index > 0 && index < words.Count + 1)
  81.         {
  82.             words.Insert(index - 1, word);
  83.         }
  84.         return;
  85.     }
  86.     public static void Replace(string word1, string word2)
  87.     {
  88.         if (words.Contains(word2))
  89.         {
  90.             words[words.IndexOf(word2)] = word1;
  91.         }
  92.         return;
  93.     }
  94. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×