Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _02_Icarus
- {
- public class Icarus
- {
- public static void Main()
- {
- var nums = Console.ReadLine().Split().Select(int.Parse).ToList();
- int index = int.Parse(Console.ReadLine());
- int damage = 1;
- while (true)
- {
- string line = Console.ReadLine();
- if (line == "Supernova")
- break;
- var tokens = line.Split().ToArray();
- var direction = tokens[0];
- var steps = int.Parse(tokens[1]);
- if (direction == "left")
- MoveLeft(nums, ref index, ref damage, steps);
- else if (direction == "right")
- MoveRight(nums, ref index, ref damage, steps);
- }
- Console.WriteLine(string.Join(" ", nums));
- }
- static void MoveRight(List<int> nums, ref int index, ref int damage, int steps)
- {
- for (int i = 1; i <= steps; i++)
- {
- index++;
- if (index > nums.Count - 1)
- {
- damage++;
- index = 0;
- }
- SubstractCurrentNumber(nums, index, damage);
- }
- }
- private static void SubstractCurrentNumber(List<int> nums, int index, int damage)
- {
- nums[index] -= damage;
- }
- static void MoveLeft(List<int> nums, ref int index, ref int damage, int steps)
- {
- for (int i = 1; i <= steps; i++)
- {
- index--;
- if (index == -1)
- {
- damage++;
- index = nums.Count - 1;
- }
- SubstractCurrentNumber(nums, index, damage);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement