Advertisement
Guest User

Untitled

a guest
Feb 18th, 2020
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.62 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace ArcheryT
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             int[] array = Console.ReadLine().Split('|').Select(int.Parse).ToArray();
  11.             string input;
  12.             int iskrenPoints = 0;
  13.             while ((input = Console.ReadLine()) != "Game over")
  14.             {
  15.                 string[] command = input.Split(' ', '@');
  16.                 if (command[0] == "Shoot" && command[1] == "Left")
  17.                 {
  18.                     int index = int.Parse(command[2]);
  19.                     int length = int.Parse(command[3]);
  20.                     if (index <= array.Length - 1 && index >= 0)
  21.                     {
  22.                         while (length != 0)
  23.                         {
  24.  
  25.                             if (index > 0) //if it's not on the first index
  26.                             {
  27.                                 index--;
  28.                                 length--;
  29.                             }
  30.                             else if (index == 0) //if it's on the first index
  31.                             {
  32.                                 index = array.Length - 1;
  33.                                 length--;
  34.                             }
  35.                         }
  36.  
  37.                         if (array[index] >= 5) //if there is enough points
  38.                         {
  39.                             array[index] -= 5;
  40.                             iskrenPoints += 5;
  41.                         }
  42.                         else //if there isn't is enough points
  43.                         {
  44.                             iskrenPoints += array[index];
  45.                             array[index] = 0;
  46.                         }
  47.  
  48.  
  49.  
  50.                     }
  51.  
  52.  
  53.                 }
  54.                 else if (command[0] == "Shoot" && command[1] == "Right")
  55.                 {
  56.  
  57.                     int index = int.Parse(command[2]);
  58.                     int length = int.Parse(command[3]);
  59.  
  60.                     // if the index is valid
  61.                     if (index >= 0 && index <= array.Length - 1)
  62.                     {
  63.                         //while we are going to the target index
  64.                         while (length != 0)
  65.                         {
  66.  
  67.  
  68.                             if (index < array.Length - 1)// if it's not on the last index
  69.                             {
  70.                                 index++;
  71.                                 length--;
  72.                             }
  73.                             else if (index == array.Length - 1) //// if it's on the last index
  74.                             {
  75.                                 index = 0;
  76.                                 length--;
  77.                             }
  78.                         }
  79.  
  80.                         if (array[index] >= 5)
  81.                         {
  82.                             array[index] -= 5;
  83.                             iskrenPoints += 5;
  84.                         }
  85.                         else
  86.                         {
  87.                             iskrenPoints += array[index];
  88.                             array[index] = 0;
  89.                         }
  90.                     }
  91.  
  92.  
  93.  
  94.                 }
  95.                 else if (command[0] == "Reverse")
  96.                 {
  97.                     Array.Reverse(array);
  98.                 }
  99.  
  100.  
  101.             }
  102.             for (int i = 0; i < array.Length - 1; i++)
  103.             {
  104.                 Console.Write(array[i] + " - ");
  105.             }
  106.  
  107.             Console.WriteLine(array[array.Length - 1]);
  108.             Console.WriteLine($"Iskren finished the archery tournament with {iskrenPoints} points!");
  109.  
  110.         }
  111.     }
  112.  
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement