BubaLazi

Dictionaries 01 Odd Occurrences

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