emilia98

Wormhole

Aug 16th, 2017
363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.71 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace _03.Wormhole
  5. {
  6.     class Wormhole
  7.     {
  8.         static void Main()
  9.         {
  10.             int[] wormhole = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  11.             int len = wormhole.Length;
  12.  
  13.             int index = 0;
  14.             int steps = 0;
  15.             while (index != len)
  16.             {
  17.                 int currentInteger = wormhole[index];
  18.                 if (currentInteger != 0)
  19.                 {
  20.                     wormhole[index] = 0;
  21.                     index = currentInteger;                  
  22.                 }
  23.                 index++;
  24.                 steps++;
  25.             }
  26.             Console.WriteLine(steps);
  27.         }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment