elena1234

OddOccurrences-withDictionary

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