Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace _02ExtractOddStrings
- {
- class OddStrings
- {
- static void ExtractOddOccuredStrings(string[] str, Dictionary<string, int> dictionary)
- {
- foreach (var s in str)
- {
- int occurs = 1;
- if (dictionary.ContainsKey(s))
- {
- occurs = dictionary[s] + 1;
- }
- dictionary[s] = occurs;
- }
- }
- static void Print(Dictionary<string, int> dict)
- {
- int size = dict.Count;
- int count = 0;
- Console.Write("{");
- foreach (var item in dict)
- {
- if (item.Value %2==1)
- {
- Console.Write("{0}", item.Key, item.Value);
- }
- if (count < size-2)
- {
- Console.Write(", ");
- }
- count++;
- }
- Console.WriteLine("}");
- }
- static void Main(string[] args)
- {
- Dictionary<string, int> dictionary = new Dictionary<string, int>();
- string[] str = { "C#", "SQL", "PHP", "PHP", "SQL", "SQL" };
- ExtractOddOccuredStrings(str, dictionary);
- Print(dictionary);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment