Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace classwork2
- {
- class Program
- {
- static void Main()
- {
- var initialArray = new int[9] { 1, 2, 9, 8, 9, 9, 4, 2, 2 };
- var arrayIndexes = ArrayIndexesNumbers(initialArray);
- var numberInput = int.Parse(Console.ReadLine());
- if (arrayIndexes.ContainsKey(numberInput))
- {
- var index = arrayIndexes[numberInput];
- Console.WriteLine(index);
- }
- else
- Console.WriteLine(-1);
- }
- public static Dictionary<int, int> ArrayIndexesNumbers(int[] initialArray)
- {
- var arrayIndices = new Dictionary<int, int>();
- for (var index = 0; index < initialArray.Length; index++)
- {
- var number = initialArray[index];
- if (!arrayIndices.ContainsKey(number))
- arrayIndices[number] = index;
- }
- return arrayIndices;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement