GerganaTsirkova

Icarus

Mar 19th, 2018
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.38 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _2.Icarus
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             List<int> arr = Console.ReadLine().Split().Select(int.Parse).ToList();
  12.             int startPos = int.Parse(Console.ReadLine());
  13.             string[] direction = Console.ReadLine().Split().ToArray();
  14.             int damage = 1;
  15.             while (direction[0] != "Supernova")
  16.             {
  17.                 int steps = int.Parse(direction[1]);
  18.                 string dir = direction[0];
  19.                 if (dir=="right")
  20.                 {
  21.                     int countDamage = 0;
  22.                     for (int i = startPos + 1; i <= startPos+steps; i++)
  23.                     {
  24.                         if (i <= arr.Count - 1)
  25.                         {
  26.                             arr[i] -= damage;
  27.                             if(i==startPos+steps)
  28.                             {
  29.                                 startPos = i;
  30.                                 break;
  31.                             }
  32.                         }
  33.                         else if (i >= arr.Count)
  34.                         {
  35.                             countDamage++;
  36.                             if ((countDamage == 1)||(i % arr.Count == 0))
  37.                             {
  38.                                 damage++;
  39.                             }
  40.                             arr[i % arr.Count] -= damage;
  41.                             if(i==startPos+steps)
  42.                             {
  43.                                 startPos = i % arr.Count;
  44.                                 break;
  45.                             }
  46.                         }
  47.                     }
  48.                 }
  49.                 else if(dir=="left")
  50.                 {
  51.                     int countDamage = 0;
  52.                     for (int i = startPos-1; i >= startPos-steps; i--)
  53.                     {
  54.                         if(i>=0)
  55.                         {
  56.                             arr[i] -= damage;
  57.                             if(i==startPos-steps)
  58.                             {
  59.                                 startPos = startPos - steps;
  60.                                 break;
  61.                             }
  62.                         }
  63.                         else
  64.                         {
  65.                             int temp = i;
  66.                             int help = arr.Count;
  67.                             i += arr.Count;
  68.                             if(i<0)
  69.                             {
  70.                                 i += arr.Count;
  71.                                 help *= 2;
  72.                             }
  73.                             countDamage++;
  74.                             if ((countDamage==1)||(i % arr.Count==0))
  75.                             {
  76.                                 damage++;
  77.                             }
  78.                             arr[i] -= damage;
  79.                             i = temp;
  80.                             if(i== startPos - steps)
  81.                             {
  82.                                 startPos = i + help;
  83.                                 break;
  84.                             }
  85.                         }
  86.                     }
  87.                    
  88.                 }
  89.                 direction = Console.ReadLine().Split().ToArray();
  90.             }
  91.             Console.WriteLine(string.Join(" ",arr));
  92.         }
  93.     }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment