Advertisement
Guest User

Untitled

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