Advertisement
Guest User

Untitled

a guest
Dec 10th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.84 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.                     if (array.Length<startIndex)
  21.                     {
  22.                         command = Console.ReadLine();
  23.                         continue;
  24.                     }
  25.                     if (startIndex - lenght < 0)
  26.                     {
  27.                         startIndex = Math.Abs(startIndex - lenght);
  28.                         if (array.Length - lenght < 0)
  29.                         {
  30.                             lenght = Math.Abs( array.Length - lenght);
  31.                             if (array.Length - lenght < 0)
  32.                             {
  33.                                 lenght= Math.Abs(array.Length - lenght);
  34.                             }
  35.                             if (array[array.Length - lenght] >= 5)
  36.                             {
  37.                                 array[array.Length - lenght] -= 5;
  38.                                 totalPoints += 5;
  39.                             }
  40.                             else
  41.                             {
  42.                                 var target = array[startIndex];
  43.                                 totalPoints += target;
  44.                                 array[target] = 0;
  45.                             }
  46.                         }
  47.                         var pointsAtArray = array[array.Length - lenght];//index
  48.  
  49.                         if (array[array.Length - lenght] >= 5)
  50.                         {
  51.                             array[array.Length - lenght] -= 5;
  52.                             totalPoints += 5;
  53.                         }
  54.                         else
  55.                         {
  56.                             var target = array[startIndex];
  57.                             totalPoints += target;
  58.                             array[target] = 0;
  59.                         }
  60.                         //totalPoints += Math.Abs(array[array.Length - lenght] - 5);
  61.                         //array[array.Length - lenght] -= 5;
  62.                     }
  63.                 }
  64.                 else if (command.Contains("Right"))
  65.                 {
  66.                     var startIndex = int.Parse(command.Split('@')[1]);
  67.                     var lenght = int.Parse(command.Split('@')[2]);
  68.  
  69.                     if (array.Length < startIndex)
  70.                     {
  71.                         command = Console.ReadLine();
  72.                         continue;
  73.                     }
  74.                     // not sure about >=/>
  75.                     if (array.Length >= startIndex + lenght)
  76.                     {
  77.                         array[startIndex + lenght + 1] -= 5;
  78.                         totalPoints += 5;
  79.                     }
  80.                     else
  81.                     {
  82.                         lenght = Math.Abs(array.Length - (startIndex + lenght));
  83.                         startIndex = 0;
  84.  
  85.                         if (array.Length < lenght)
  86.                         {
  87.                             command = Console.ReadLine();
  88.                             continue;
  89.                             //lenght = Math.Abs(array.Length - lenght);
  90.                         }
  91.  
  92.                         if (array[lenght] >= 5)
  93.                         {
  94.                             array[lenght] -= 5;
  95.                             totalPoints += 5;
  96.                         }
  97.                         else
  98.                         {
  99.                             var points = Math.Abs(array[lenght] - 5);
  100.                             totalPoints += points;
  101.                             array[lenght] = 0;
  102.                         }
  103.                     }
  104.                 }
  105.                 else if (command == "Reverse")
  106.                 {
  107.                     array = array.Reverse().ToArray();
  108.                 }
  109.  
  110.                 command = Console.ReadLine();
  111.             }
  112.  
  113.             Console.WriteLine(string.Join(" - ", array));
  114.             Console.WriteLine($"Iskren finished the archery tournament with {totalPoints} points!");
  115.         }
  116.     }
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement