Advertisement
alidzhikov

CountSymbols

May 8th, 2015
630
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.67 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. class CountSymbols
  5. {
  6.     static void Main()
  7.     {
  8.         string inputText = Console.ReadLine();
  9.  
  10.         SortedDictionary<char, int> occurrences = new SortedDictionary<char, int>();
  11.         foreach (char symbol in inputText)
  12.         {
  13.             if (occurrences.ContainsKey(symbol))
  14.             {
  15.                 occurrences[symbol]++;
  16.             }
  17.             else
  18.             {
  19.                 occurrences.Add(symbol, 1);
  20.             }
  21.         }
  22.  
  23.         foreach (KeyValuePair<char, int> pair in occurrences)
  24.         {
  25.             Console.WriteLine("{0}: {1} time/s", pair.Key, pair.Value);
  26.         }
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement