Advertisement
DyNaMiXx7

Untitled

Mar 24th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.85 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace _01CountCharsInAString
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             string characters = Console.ReadLine();
  11.             var counts = new Dictionary<char, int>();
  12.  
  13.             foreach (char character in characters)
  14.             {
  15.                 if (character == ' ')
  16.                 {
  17.                     continue;
  18.                 }
  19.  
  20.                 if (counts.ContainsKey(character))
  21.                 {
  22.                     counts[character]++;
  23.                 }
  24.                 else
  25.                 {
  26.                     counts.Add(character, 1);
  27.                 }
  28.             }
  29.  
  30.             foreach (var count in counts)
  31.             {
  32.                 Console.WriteLine($"{count.Key} -> {count.Value}");
  33.             }
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement