Advertisement
-Annie-

CountSymbols

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