Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace Problem2
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[] particles = Console.ReadLine()
- .Split("|", StringSplitOptions.RemoveEmptyEntries)
- .ToArray();
- while (true)
- {
- string line = Console.ReadLine();
- if (line == "Done")
- {
- break;
- }
- string[] tokens = line.Split(' ', StringSplitOptions.RemoveEmptyEntries);
- string command = tokens[0];
- string instruction = tokens[1];
- if (command == "Move")
- {
- int index = int.Parse(tokens[2]);
- if (IsValidIndex(particles, index))
- {
- if (instruction == "Left" && IsPossibleMoveLeft(particles, index))
- {
- string oldElement = particles[index];
- particles[index] = particles[index - 1];
- particles[index - 1] = oldElement;
- }
- else if (instruction == "Right" && IsPossibleMoveRight(particles, index))
- {
- string oldElement = particles[index];
- particles[index] = particles[index + 1];
- particles[index + 1] = oldElement;
- }
- }
- }
- else if (command == "Check")
- {
- if (instruction == "Even")
- {
- for (int i = 0; i < particles.Length; i++)
- {
- if (i % 2 == 0)
- {
- Console.Write($"{particles[i]} ");
- }
- }
- Console.WriteLine();
- }
- else if (instruction == "Odd")
- {
- for (int i = 0; i < particles.Length; i++)
- {
- if (i % 2 == 1)
- {
- Console.Write($"{particles[i]} ");
- }
- }
- Console.WriteLine();
- }
- }
- }
- string weapon = string.Concat(particles);
- Console.WriteLine($"You crafted {weapon}!");
- //string weapon = String.Empty;
- //foreach (string particle in particles)
- //{
- // weapon += particle;
- //}
- //Console.WriteLine($"You crafted {weapon}!");
- }
- private static bool IsPossibleMoveRight(string[] parts, int index)
- {
- return index + 1 < parts.Length;
- }
- private static bool IsPossibleMoveLeft(string[] parts, int index)
- {
- return index - 1 >= 0;
- }
- private static bool IsValidIndex(string[] parts, int index)
- {
- return index >= 0 && index < parts.Length;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement