Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- namespace SantasGifts
- {
- class Program
- {
- static void Main(string[] args)
- {
- int commandNumbers = int.Parse(Console.ReadLine());
- var houses = Console.ReadLine().Split().ToList();
- int index = 0;
- for (int i = 0; i < commandNumbers; i++)
- {
- int currentIndex = index;
- var command = Console.ReadLine().Split().ToList();
- if (command[0] == "Forward" || command[0] == "Back")
- {
- int steps = int.Parse(command[1]);
- currentIndex += (command[0] == "Forward" ? steps : -steps);
- if(currentIndex >= 0 && currentIndex < houses.Count)
- {
- index = currentIndex;
- houses.RemoveAt(index);
- }
- }
- else if (command[0] == "Gift")
- {
- currentIndex = int.Parse(command[1]);
- if (currentIndex >= 0 && currentIndex < houses.Count)
- {
- index = currentIndex;
- houses.Insert(index, command[2]);
- }
- }
- else if (command[0] == "Swap")
- {
- int index1 = houses.IndexOf(command[1]),
- index2 = houses.IndexOf(command[2]);
- if (index1 != -1 && index2 != -1)
- {
- string value = houses[index1];
- houses[index1] = houses[index2];
- houses[index2] = value;
- }
- }
- }
- Console.WriteLine($"Position: {index}");
- if (houses.Count() > 0)
- {
- Console.WriteLine(string.Join(", ", houses));
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement