Advertisement
Spocoman

01. Count Chars in a String

Apr 8th, 2023
877
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.50 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace CountCharsInAString
  6. {
  7.     class Program
  8.     {
  9.         public static void Main()
  10.         {
  11.             var charsCount = Console.ReadLine()
  12.                 .Replace(" ", "")
  13.                 .GroupBy(x => x)
  14.                 .ToDictionary(x => x.Key, x => x.Count());
  15.  
  16.             foreach (var chr in charsCount)
  17.             {
  18.                 Console.WriteLine($"{chr.Key} -> {chr.Value}");
  19.             }
  20.         }
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement