mausha

WormHole

May 2nd, 2017
399
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.68 KB | None | 0 0
  1. namespace Wormhole
  2. {
  3.     using System;
  4.     using System.Linq;
  5.  
  6.     public class Hole
  7.     {
  8.         public static void Main()
  9.         {
  10.             var wormholes = Console.ReadLine().Split().Select(int.Parse).ToList();
  11.  
  12.             var counter = 0;
  13.             for (int i = 0; i < wormholes.Count; i++)
  14.             {
  15.                 if (wormholes[i] != 0)
  16.                 {
  17.                     var index = wormholes[i] - 1;
  18.                     wormholes[i] = 0;
  19.                     i = index;
  20.                 }
  21.                 else
  22.                 {
  23.                     counter++;
  24.                 }
  25.             }
  26.  
  27.             Console.WriteLine(counter);
  28.         }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment