gabi11

Sets & Dictionaries Advanced - 05. Count Symbols

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