Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Linq;
- using System.Threading;
- namespace ConsoleApp1
- {
- class Exam
- {
- static void Main(string[] args)
- {
- List<string> sentence = Console.ReadLine().Split().ToList();
- string[] command = Console.ReadLine().Split().ToArray();
- while (command[0] != "Stop")
- {
- if (command[0] == "Delete")
- {
- int index = int.Parse(command[1]) + 1;
- if (index >= 0 && index < sentence.Count)
- {
- sentence.RemoveAt(index);
- }
- }
- if (command[0] == "Swap")
- {
- if (sentence.Contains(command[1]) && sentence.Contains(command[2]))
- {
- int index1 = sentence.IndexOf(command[1]);
- int index2 = sentence.IndexOf(command[2]);
- sentence[index1] = command[2];
- sentence[index2] = command[1];
- }
- }
- if (command[0] == "Put")
- {
- int index = int.Parse(command[2]) - 1;
- if (index >= 0 && index <= sentence.Count)
- {
- sentence.Insert(index, command[1]);
- }
- }
- if (command[0] == "Sort")
- {
- //sentence.OrderByDescending(x => x);
- //sentence.Sort();
- //sentence.Reverse();
- sentence.Sort((x, y) => y.CompareTo(x));
- }
- if (command[0] == "Replace")
- {
- if (sentence.Contains(command[2]))
- {
- int index = sentence.IndexOf(command[2]);
- sentence[index] = command[1];
- }
- }
- command = Console.ReadLine().Split().ToArray();
- }
- Console.WriteLine(string.Join(" ", sentence));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement