Advertisement
optybg

Untitled

May 10th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.91 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace Wormhole
  7. {
  8.     public class Wormhole
  9.     {
  10.         public static void Main()
  11.         {
  12.             var input = Console.ReadLine();
  13.             var wormholes = input
  14.                 .Split(new[] { ' '}, StringSplitOptions.RemoveEmptyEntries)
  15.                 .Select(int.Parse)
  16.                 .ToArray();
  17.  
  18.             var counter = 0;
  19.  
  20.             for (int i = 0; i < wormholes.Length; i++)
  21.             {
  22.                 if (wormholes[i] == 0)
  23.                 {
  24.                     counter++;
  25.                 }
  26.                 else
  27.                 {
  28.                     var realI = i;
  29.                     i = (wormholes[i]-1);
  30.                     wormholes[realI] = 0;
  31.                    // counter++;
  32.  
  33.                 }
  34.             }
  35.  
  36.             Console.WriteLine(counter);
  37.  
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement