HRusev

LadyBugs

May 31st, 2024 (edited)
608
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.28 KB | Source Code | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Linq;
  5. using System.Reflection.Metadata;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8.  
  9. class LadyBugs
  10. {
  11.     static void decodingComand(string line, ref long startIndex, ref long flyIndex, ref bool isRight)
  12.     {
  13.         string [] comand = line.Split(' ');
  14.         startIndex = int.Parse(comand[0]);
  15.         flyIndex = int.Parse(comand[2]);
  16.         if(comand[1] == "right")
  17.             isRight = true;
  18.         else
  19.             isRight = false;    
  20.     }
  21.  
  22.     static void move(long startIndex, long flyIndex, ref int[] field, bool isRight)
  23.     {
  24.         if(field[startIndex] == 1)
  25.         {
  26.             if(!isRight)
  27.                 flyIndex *= -1;
  28.             long newPosition;
  29.             newPosition = startIndex + flyIndex;
  30.             //Out of range
  31.             if(newPosition > (field.Length - 1) || newPosition < 0)
  32.             {
  33.                 field[startIndex] = 0;
  34.                 return;
  35.             }
  36.  
  37.             while(true)
  38.             {
  39.                
  40.                 if(field[newPosition] == 0)
  41.                 {
  42.                     field[startIndex] = 0;
  43.                     field[newPosition] = 1;
  44.                     return;
  45.                 }
  46.  
  47.                 newPosition += flyIndex;
  48.                 if(newPosition > (field.Length - 1) || newPosition < 0)
  49.                 {
  50.                     field[startIndex] = 0;
  51.                     return;
  52.                 }
  53.             }
  54.  
  55.         }
  56.     }
  57.  
  58.    
  59.     static void Main()
  60.     {
  61.  
  62.         long size = long.Parse(Console.ReadLine());
  63.         string [] cordString = Console.ReadLine().Split(' ');
  64.         int [] field = new int[size];
  65.  
  66.         long pos;
  67.         foreach(string elem in cordString)
  68.         {
  69.             pos = long.Parse(elem);
  70.             field[pos] = 1;
  71.         }
  72.         long start = 0, fly = 0;
  73.         bool isRight = false;
  74.         string line = Console.ReadLine();
  75.         while(line != "end")
  76.         {
  77.             decodingComand(line, ref start, ref fly, ref isRight);
  78.             move(start, fly, ref field, isRight);
  79.            
  80.             line = Console.ReadLine();
  81.         }
  82.  
  83.         Console.WriteLine(String.Join(" ", field));
  84.  
  85.        
  86.     }
  87. }
  88.  
  89. /*
  90.  
  91.  
  92. */
  93.  
Tags: LadyBugs
Advertisement
Add Comment
Please, Sign In to add comment