Advertisement
Aborigenius

ArrayElementEqualToTheirIndex

Jun 19th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.69 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ElementsEqualToIndex
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string n = Console.ReadLine();
  14.             int[] MyArray = n.Split(' ').Select(x => Convert.ToInt32(x)).ToArray();
  15.  
  16.             string result = String.Empty;
  17.  
  18.             for (int i = 0; i < MyArray.Length; i++)
  19.             {
  20.                 if (MyArray[i] == i)
  21.                 {
  22.                     result += i;
  23.                     result += " ";
  24.                 }
  25.             }
  26.             Console.WriteLine(result);
  27.         }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement