03. The Final Quest
Здравейте! Judge ми дава 50/100, ще може ли някой да ми помогне? Благодаря предварително! :)
Линк към Judge --> https://judge.softuni.bg/Contests/Practice/Index/1555#2
Моето решение:
using System;
using System.Linq;
using System.Collections.Generic;
namespace Courses
{
class Program
{
static void Main(string[] args)
{
var list = Console.ReadLine().Split(" ").ToList();
string command = Console.ReadLine();
while(command != "Stop")
{
var tokens = command.Split(" ").ToList();
if (tokens[0] == "Delete")
{
int indexFirst = int.Parse(tokens[1]) + 1;
list.RemoveAt(indexFirst);
}
else if (tokens[0] == "Swap")
{
string firstWord = tokens[1];
string secondWord = tokens[2];
if (list.Contains(firstWord) && list.Contains(secondWord))
{
int indexFirst = list.IndexOf(firstWord);
int indexSecond = list.IndexOf(secondWord);
list[indexFirst] = secondWord;
list[indexSecond] = firstWord;
}
}
else if(tokens[0] == "Put")
{
string word = tokens[1];
int indexFirst = int.Parse(tokens[2]) - 1;
if (list.Contains(word))
{
list.Insert(indexFirst,word);
}
}
else if(tokens[0] == "Sort")
{
list.Sort();
list.Reverse();
}
else if(tokens[0] == "Replace")
{
string firstWord = tokens[1];
string secondWord = tokens[2];
if(list.Contains(secondWord))
{
int firstIndex = list.IndexOf(secondWord);
list.RemoveAt(firstIndex);
list.Insert(firstIndex, firstWord);
}
}
command = Console.ReadLine();
}
Console.WriteLine(String.Join(" ", list));
}
}
}