Advertisement
silvana1303

final quest

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