Advertisement
elena1234

PrintAllUniqueElementsInArray

Sep 25th, 2020 (edited)
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.88 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Dictionary
  6. {
  7.     class MainClass
  8.     {
  9.         public static void Main()
  10.         {
  11.             int[] numbers = Console.ReadLine().Split().Select(int.Parse).ToArray();
  12.  
  13.             Dictionary<int, int> dictionary = new Dictionary<int, int>();
  14.  
  15.             for (int i = 0; i <= numbers.Length-1; i++)
  16.             {
  17.                 if (dictionary.ContainsKey(numbers[i]) == false)
  18.                 {
  19.                     dictionary[numbers[i]] = 1;
  20.                 }
  21.  
  22.                 else
  23.                 {
  24.                     dictionary[numbers[i]]++;
  25.                 }
  26.             }
  27.  
  28.             var filteredDict = dictionary.Where(x => x.Value == 1).ToDictionary(x=> x.Key, x=> x.Value);
  29.             Console.WriteLine(string.Join(" ", filteredDict.Keys));
  30.          
  31.         }
  32.  
  33.       }
  34.  
  35.     }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement