Advertisement
YavorGrancharov

Wormhole

Aug 19th, 2017
126
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 Wormhole
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             int[] wholes = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  11.  
  12.             int count = 0;
  13.             int currentPosition = 0;
  14.             for (int index = 0; index < wholes.Length; index++)
  15.             {
  16.                 if (wholes[index] != 0 && index != -1)
  17.                 {
  18.                     currentPosition = wholes[index];
  19.                     wholes[index] = 0;
  20.                     index = currentPosition;
  21.                    
  22.                 }
  23.                 count++;
  24.             }
  25.             Console.WriteLine(count);
  26.         }
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement