Advertisement
Guest User

Untitled

a guest
Nov 24th, 2017
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _02_Icarus
  6. {
  7. public class Icarus
  8. {
  9. public static void Main()
  10. {
  11. var nums = Console.ReadLine().Split().Select(int.Parse).ToList();
  12.  
  13. int index = int.Parse(Console.ReadLine());
  14. int damage = 1;
  15.  
  16. while (true)
  17. {
  18. string line = Console.ReadLine();
  19. if (line == "Supernova")
  20. break;
  21.  
  22. var tokens = line.Split().ToArray();
  23. var direction = tokens[0];
  24. var steps = int.Parse(tokens[1]);
  25.  
  26. if (direction == "left")
  27. MoveLeft(nums, ref index, ref damage, steps);
  28. else if (direction == "right")
  29. MoveRight(nums, ref index, ref damage, steps);
  30. }
  31.  
  32. Console.WriteLine(string.Join(" ", nums));
  33. }
  34.  
  35. static void MoveRight(List<int> nums, ref int index, ref int damage, int steps)
  36. {
  37. for (int i = 1; i <= steps; i++)
  38. {
  39. index++;
  40. if (index > nums.Count - 1)
  41. {
  42. damage++;
  43. index = 0;
  44. }
  45.  
  46. SubstractCurrentNumber(nums, index, damage);
  47. }
  48. }
  49.  
  50. private static void SubstractCurrentNumber(List<int> nums, int index, int damage)
  51. {
  52. nums[index] -= damage;
  53. }
  54.  
  55. static void MoveLeft(List<int> nums, ref int index, ref int damage, int steps)
  56. {
  57. for (int i = 1; i <= steps; i++)
  58. {
  59. index--;
  60. if (index == -1)
  61. {
  62. damage++;
  63. index = nums.Count - 1;
  64. }
  65.  
  66. SubstractCurrentNumber(nums, index, damage);
  67. }
  68. }
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement