Advertisement
grubcho

Odd Occurrences - Dictionaries

Jul 9th, 2017
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.98 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 odd_occurances
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Dictionary<string, int> words = new Dictionary<string, int>();
  14.             string[] inputWords = Console.ReadLine().ToLower().Split(' ');
  15.             for (int i = 0; i < inputWords.Length; i++)
  16.             {
  17.                 if (!words.ContainsKey(inputWords[i]))
  18.                 {
  19.                     words.Add(inputWords[i], 0);
  20.                 }
  21.                 words[inputWords[i]]++;
  22.             }
  23.             List<string> result = new List<string>();
  24.             foreach (KeyValuePair<string, int> item in words)
  25.             {
  26.                 if (item.Value % 2 == 1)
  27.                 {
  28.                     result.Add(item.Key);
  29.                 }
  30.             }
  31.             Console.WriteLine(string.Join(", ", result));
  32.         }
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement