Advertisement
Guest User

10.LadyBugs

a guest
Feb 15th, 2021
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.69 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace _10._1Калинки
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             int arrRange = int.Parse(Console.ReadLine());
  11.             int[] indexesWith_1_OnThem = Console.ReadLine()
  12.                 .Split(' ')
  13.                 .Select(int.Parse)
  14.                 .ToArray();
  15.  
  16.             int[] resultArr = new int[arrRange];
  17.            
  18.  
  19.             for (int i = 0; i < indexesWith_1_OnThem.Length; i++)
  20.             {
  21.                 if (indexesWith_1_OnThem[i] > -1 && indexesWith_1_OnThem[i] < resultArr.Length)
  22.                 {
  23.                     resultArr[indexesWith_1_OnThem[i]] = 1;
  24.                 }
  25.             }
  26.             while (true)
  27.             {
  28.                 string[] arrCommands = Console.ReadLine()
  29.                     .Split()
  30.                     .ToArray();
  31.                 if (arrCommands[0] == "end")
  32.                 {
  33.                     Console.WriteLine(string.Join(' ', resultArr));
  34.                     return;
  35.                 }
  36.  
  37.                 int insectOnIndex = int.Parse(arrCommands[0]);
  38.                 int toMoveWith = int.Parse(arrCommands[2]);
  39.  
  40.                 if (insectOnIndex < 0 || insectOnIndex >= arrRange)
  41.                 {
  42.                     continue;
  43.                 }
  44.                 if (resultArr[insectOnIndex] == 0) // must be 1
  45.                 {
  46.                     continue;
  47.                 }
  48.  
  49.  
  50.  
  51.                 if (toMoveWith < 0 && arrCommands[1] == "left")
  52.                 {
  53.                     arrCommands[1] = "right";
  54.                     toMoveWith = Math.Abs(toMoveWith);
  55.                 }
  56.                 else if (toMoveWith < 0 && arrCommands[1] == "right")
  57.                 {
  58.                     arrCommands[1] = "left";
  59.                     toMoveWith = Math.Abs(toMoveWith);
  60.                 }
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.                 while (true)
  69.                 {
  70.                     if (arrCommands[1] == "right")
  71.                     {
  72.                        
  73.  
  74.                         if (insectOnIndex + toMoveWith >= arrRange || insectOnIndex + toMoveWith < 0) // flies away
  75.                         {
  76.                             resultArr[insectOnIndex] = 0;
  77.                             break;
  78.                         }
  79.                         if (resultArr[insectOnIndex + toMoveWith] == 1)
  80.                         {
  81.                             toMoveWith += 1;
  82.                         }
  83.                         else if (resultArr[insectOnIndex + toMoveWith] == 0)
  84.                         {
  85.                             resultArr[insectOnIndex + toMoveWith] = 1;
  86.                             resultArr[insectOnIndex] = 0;
  87.                             break;
  88.  
  89.                         }
  90.                     }
  91.                     else if (arrCommands[1] == "left")
  92.                     {
  93.                        
  94.  
  95.                         if (insectOnIndex - toMoveWith >= arrRange || insectOnIndex - toMoveWith < 0) // flies away
  96.                         {
  97.                             resultArr[insectOnIndex] = 0;
  98.                             break;
  99.                         }
  100.                         if (resultArr[insectOnIndex - toMoveWith] == 1)
  101.                         {
  102.                             toMoveWith -= 1;
  103.                         }
  104.                         else if (resultArr[insectOnIndex - toMoveWith] == 0)
  105.                         {
  106.                             resultArr[insectOnIndex - toMoveWith] = 1;
  107.                             resultArr[insectOnIndex] = 0;
  108.                             break;
  109.                         }
  110.                     }
  111.                 }
  112.                
  113.              
  114.             }
  115.         }
  116.     }
  117. }
  118.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement