Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Weaponsmith
- {
- class MainClass
- {
- public static void Main(string[] args)
- {
- List<string> listOfParticles = Console.ReadLine().Split('|').ToList();
- string command = string.Empty;
- while ((command = Console.ReadLine()) != "Done")
- {
- string[] commandArray = command.Split();
- if (commandArray[0] == "Move" && commandArray[1] == "Left")
- {
- int index = int.Parse(commandArray[2]);
- MoveLeft(listOfParticles, index);
- }
- else if (commandArray[0] == "Move" && commandArray[1] == "Right")
- {
- int index = int.Parse(commandArray[2]);
- MoveRight(listOfParticles, index);
- }
- else if (commandArray[0] == "Check" && commandArray[1] == "Even")
- {
- PrintElementsAtEvenIndex(listOfParticles);
- }
- else if (commandArray[0] == "Check" && commandArray[1] == "Odd")
- {
- PrintElementsAtOddIndex(listOfParticles);
- }
- }
- Console.Write($"You crafted ");
- Console.WriteLine(string.Join("",listOfParticles)+"!");
- }
- private static void PrintElementsAtOddIndex(List<string> listOfParticles)
- {
- string particlesOnOddIndex = string.Empty;
- for (int i = 0; i <= listOfParticles.Count - 1; i++)
- {
- if (i % 2 != 0)
- {
- particlesOnOddIndex += listOfParticles[i] + " ";
- }
- }
- Console.WriteLine(particlesOnOddIndex.TrimEnd());
- }
- private static void PrintElementsAtEvenIndex(List<string> listOfParticles)
- {
- string particlesOnEvenIndex = string.Empty;
- for (int i = 0; i <= listOfParticles.Count - 1; i++)
- {
- if (i % 2 == 0)
- {
- particlesOnEvenIndex += listOfParticles[i] + " ";
- }
- }
- Console.WriteLine(particlesOnEvenIndex.TrimEnd());
- }
- private static void MoveRight(List<string> listOfParticles, int index)
- {
- if (index >= 0 && index <= listOfParticles.Count - 2)
- {
- string currentParticle = listOfParticles[index];
- string nextParticle = listOfParticles[index + 1];
- listOfParticles.Insert(index + 1, currentParticle);
- listOfParticles.RemoveAt(index + 2);
- listOfParticles.Insert(index, nextParticle);
- listOfParticles.RemoveAt(index + 1);
- }
- }
- private static void MoveLeft(List<string> listOfParticles, int index)
- {
- if (index >= 1 && index <= listOfParticles.Count - 1)
- {
- string currentParticle = listOfParticles[index];
- string prevParticle = listOfParticles[index - 1];
- listOfParticles.Insert(index - 1, currentParticle);
- listOfParticles.RemoveAt(index);
- listOfParticles.Insert(index, prevParticle);
- listOfParticles.RemoveAt(index + 1);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement