Advertisement
radidim

10.LadyBugs (C# Shell App Paste)

Jan 12th, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.51 KB | None | 0 0
  1. using System.IO;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace CSharp_Shell
  6. {
  7.  
  8.     public static class Program
  9.     {
  10.         public static void Main()
  11.         {
  12.            int fieldSize = int.Parse(Console.ReadLine());
  13.            
  14.            int[] indexes = Console.ReadLine()
  15.            .Split()
  16.            .Select(int.Parse)
  17.            .ToArray();
  18.            
  19.            int[] field = new int[fieldSize];
  20.            for(int i = 0;i<indexes.Length; i++)
  21.            {
  22.               int  index = indexes[i];
  23.                if(index >=0 && index < field.Length)
  24.                {
  25.                    field[index]=1;
  26.                }
  27.            }
  28.            
  29.            while(true)
  30.            {
  31.                string command = Console.ReadLine();
  32.                
  33.                if(command == "end")
  34.                {
  35.                    break;
  36.                }
  37.                
  38.                string[] cmdArg = command
  39.                .Split()
  40.                .ToArray();
  41.                
  42.                int index = int.Parse(cmdArg[0]);
  43.                string cmd = cmdArg[1];
  44.                int flyLength = int.Parse(cmdArg[2]);
  45.                
  46.                
  47.                if(index < 0 || index > field.Length-1 || field[index]==0)
  48.                {
  49.                    continue;
  50.                }
  51.                
  52.                
  53.                field[index] = 0;
  54.                index+=flyLength;
  55.                
  56.                if(cmd == "right")
  57.                {
  58.                    while(index<field.Length && field[index]==1)
  59.                    {
  60.                        index+=flyLength;
  61.                    }
  62.                    
  63.                    if(index<field.Length)
  64.                    {
  65.                        field[index]=1;
  66.                    }
  67.                }
  68.                if(cmd == "left")
  69.                {
  70.                    while(index>=0 && field[index]==1)
  71.                    {
  72.                        index-=flyLength;
  73.                    }
  74.                    
  75.                    if(index>=0)
  76.                    {
  77.                        field[index] = 1;
  78.                    }
  79.                    
  80.                }
  81.                
  82.            }
  83.                
  84.            Console.Write(string.Join(" ", field));
  85.         }
  86.     }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement