Advertisement
MartinZarev

Untitled

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