Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- namespace The_Final_Quest_MidExam_10thOfMarch2019
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<string> sentence = Console.ReadLine()
- .Split(" ")
- .ToList();
- string instruction = Console.ReadLine();
- while (instruction != "Stop")
- {
- string[] splitedInstruction = instruction.Split(" ");
- string command = splitedInstruction[0];
- if (command == "Delete")
- {
- int index =int.Parse(splitedInstruction[1]) + 1;
- if (index > 0 && index <= sentence.Count)
- {
- sentence.RemoveAt(index);
- }
- }
- else if (command == "Swap")
- {
- string firstWord = splitedInstruction[1];
- string secondWord = splitedInstruction[2];
- int indexof1 = sentence.IndexOf(firstWord);
- int indexOf2 = sentence.IndexOf(secondWord);
- sentence[indexof1] = secondWord;
- sentence[indexOf2] = firstWord;
- }
- else if (command == "Put")
- {
- string word = splitedInstruction[1];
- int index = int.Parse(splitedInstruction[2]) - 1;
- if (index > 0 && index <= sentence.Count)
- {
- sentence.Insert(index, word);
- }
- else if (index == sentence.Count - 1)
- {
- sentence.Add(word);
- }
- }
- else if (command == "Sort")
- {
- sentence.Sort();
- sentence.Reverse();
- }
- else if (command == "Replace")
- {
- string wordOne = splitedInstruction[1];
- string wordTwo = splitedInstruction[2];
- int indexOf2 = sentence.IndexOf(wordTwo);
- if (sentence.Contains(wordTwo))
- {
- sentence[indexOf2] = wordOne;
- }
- }
- instruction = Console.ReadLine();
- }
- if (instruction == "Stop")
- {
- Console.WriteLine(string.Join(" ", sentence));
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement