TheBulgarianWolf

Odd Occurrences

Feb 20th, 2021
719
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace OddOccurrences
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             Console.WriteLine("Enter your line of words(separated by space): ");
  11.             string[] words = Console.ReadLine().Split(" ");
  12.             Dictionary<string, int> occurrences = new Dictionary<string, int>();
  13.  
  14.             foreach(string word in words)
  15.             {
  16.                 string wordInLowerCase = word.ToLower();
  17.                 if (occurrences.ContainsKey(wordInLowerCase))
  18.                 {
  19.                     occurrences[wordInLowerCase]++;
  20.                 }
  21.                 else
  22.                 {
  23.                     occurrences.Add(wordInLowerCase, 1);
  24.                 }
  25.             }
  26.  
  27.             foreach(var occurrence in occurrences)
  28.             {
  29.                 if(occurrence.Value % 2 != 0)
  30.                 {
  31.                     Console.WriteLine(occurrence.Key + " ");
  32.                 }
  33.             }
  34.         }
  35.     }
  36. }
  37.  
RAW Paste Data