SHARE
TWEET

countCharsInAString

a guest Nov 15th, 2019 85 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace countCharsInAString
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             string text = Console.ReadLine();
  11.             Dictionary<char, int> letters = new Dictionary<char, int>();
  12.             for (int i = 0; i < text.Length; i++)
  13.             {
  14.                 char letter = text[i];
  15.                 if (letter != ' ')
  16.                 {
  17.                     if (!letters.ContainsKey(letter))
  18.                     {
  19.                         letters.Add(letter, 1);
  20.                     }
  21.                     else
  22.                     {
  23.                         letters[letter]++;
  24.                     }
  25.                 }
  26.             }
  27.             foreach (var item in letters)
  28.             {
  29.                 Console.WriteLine(item.Key + " -> " + item.Value);
  30.             }
  31.         }
  32.     }
  33. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top