Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 02.Odd Occurrences
- Write a program that extracts all elements from a given sequence of words that are present in it an odd number of times (case-insensitive).
- • Words are given on a single line, space separated.
- • Print the result elements in lowercase, in their order of appearance.
- Examples
- Input Output
- Java C# PHP PHP JAVA C java java c# c
- 3 5 5 hi pi HO Hi 5 ho 3 hi pi 5 hi
- a a A SQL xx a xx a A a XX c a sql xx c
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _02OddOccurrences
- {
- class Program
- {
- static void Main(string[] args)
- {
- var words = Console.ReadLine().ToLower().Split().ToArray();
- var counts = new Dictionary<string, int>();
- foreach (var item in words)
- {
- if (counts.ContainsKey(item))
- {
- counts[item]++;
- }
- else
- {
- counts.Add(item, 1);
- }
- }
- foreach (var item in counts)
- {
- if (item.Value % 2 != 0)
- {
- Console.Write(item.Key + " ");
- }
- }
- Console.WriteLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment