Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.IO;
- using System.Linq;
- using System.Collections.Generic;
- namespace CSharp_Shell
- {
- public static class Program
- {
- public static void Main()
- {
- int fieldSize = int.Parse(Console.ReadLine());
- int[] indexes = Console.ReadLine()
- .Split()
- .Select(int.Parse)
- .ToArray();
- int[] field = new int[fieldSize];
- for(int i = 0;i<indexes.Length; i++)
- {
- int index = indexes[i];
- if(index >=0 && index < field.Length)
- {
- field[index]=1;
- }
- }
- while(true)
- {
- string command = Console.ReadLine();
- if(command == "end")
- {
- break;
- }
- string[] cmdArg = command
- .Split()
- .ToArray();
- int index = int.Parse(cmdArg[0]);
- string cmd = cmdArg[1];
- int flyLength = int.Parse(cmdArg[2]);
- if(index < 0 || index > field.Length-1 || field[index]==0)
- {
- continue;
- }
- field[index] = 0;
- index+=flyLength;
- if(cmd == "right")
- {
- while(index<field.Length && field[index]==1)
- {
- index+=flyLength;
- }
- if(index<field.Length)
- {
- field[index]=1;
- }
- }
- if(cmd == "left")
- {
- while(index>=0 && field[index]==1)
- {
- index-=flyLength;
- }
- if(index>=0)
- {
- field[index] = 1;
- }
- }
- }
- Console.Write(string.Join(" ", field));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement