Advertisement
Guest User

CountOfLetters

a guest
Apr 9th, 2014
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.89 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _11_CountOfLetters
  6. {
  7.     class CountOfLetters
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.  
  12.             string[] letters = Console.ReadLine().Split(new char[] {' '}, StringSplitOptions.RemoveEmptyEntries);
  13.             Dictionary<string, int> dictionary = new Dictionary<string, int>();
  14.  
  15.             foreach (var letter in letters)
  16.             {
  17.                 int count = 0;
  18.                 if (dictionary.ContainsKey(letter))
  19.                 {
  20.                     count = dictionary[letter];
  21.                 }
  22.                 dictionary[letter] = count + 1;
  23.             }
  24.  
  25.             foreach (KeyValuePair<string, int> item in dictionary.OrderBy(key => key.ToString()))
  26.             {
  27.                 Console.WriteLine("{0} -> {1} times", item.Key, item.Value);
  28.             }
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement