Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace _09.Jump_Around
- {
- class Program
- {
- static void Main(string[] args)
- {
- var numbers = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
- var sum = numbers[0];
- var step = numbers[0];
- var index = Array.IndexOf(numbers, step);
- while (true)
- {
- try
- {
- index = Array.IndexOf(numbers, numbers[index + step]);
- step = numbers[index];
- sum += step;
- }
- catch (Exception e)
- {
- try
- {
- index = Array.IndexOf(numbers, numbers[index - step]);
- step = numbers[index];
- sum += step;
- }
- catch (Exception ex)
- {
- Console.WriteLine(sum);
- return;
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement