Advertisement
MeliDragon

Untitled

Mar 8th, 2023
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. namespace MethoodsAndStrings
  7. {
  8. internal class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. int position = int.Parse(Console.ReadLine());
  13. int[] path = Console.ReadLine().Split(',').Select(int.Parse).ToArray();
  14. string[] commands = Console.ReadLine().Split(' ');
  15. long sumForeword = 0;
  16. long sumBackwords = 0;
  17.  
  18. while (commands[0] != "exit")
  19. {
  20. int steps = int.Parse(commands[0]);
  21. string direction = commands[1];
  22. int size = int.Parse(commands[2]);
  23.  
  24. if (direction == "forward")
  25. {
  26. while(steps>0)
  27. {
  28. if (position + size >= path.Length)
  29. {
  30. position = position + size - path.Length;
  31. }
  32. else
  33. {
  34. position += size;
  35. }
  36. sumForeword += path[position];
  37. steps--;
  38. }
  39. }
  40. else if (direction == "backwards")
  41. {
  42. while (steps > 0)
  43. {
  44. if (position - size < 0)
  45. {
  46. position = position - size + path.Length;
  47. }
  48. else
  49. {
  50. position -= size;
  51. }
  52. sumBackwords += path[position];
  53. steps--;
  54. }
  55. }
  56. commands = Console.ReadLine().Split(' ');
  57. }
  58.  
  59. Console.WriteLine($"Forward: {sumForeword}");
  60. Console.WriteLine($"Backwards: {sumBackwords}");
  61. }
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement