Advertisement
Guest User

Untitled

a guest
Aug 16th, 2018
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.67 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.     class P09_JumpAround
  4.     {
  5.         static void Main(string[] args)
  6.         {
  7.             var numArray = Console.ReadLine()
  8.                 .Split(' ')
  9.                 .Select(int.Parse)
  10.                 .ToArray();
  11.             int i = 0;
  12.             int sum = 0;
  13.             while (i >= 0)
  14.             {
  15.                 if (i < numArray.Length)
  16.                 {
  17.                     sum += numArray[i];
  18.                     i = i + numArray[i] < numArray.Length ?
  19.                         i + numArray[i] :
  20.                         i - numArray[i];
  21.                 }
  22.             }
  23.  
  24.             Console.WriteLine(sum);
  25.         }
  26.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement