Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace _01CountCharsInAString
- {
- class Program
- {
- static void Main(string[] args)
- {
- string characters = Console.ReadLine();
- var counts = new Dictionary<char, int>();
- foreach (char character in characters)
- {
- if (character == ' ')
- {
- continue;
- }
- if (counts.ContainsKey(character))
- {
- counts[character]++;
- }
- else
- {
- counts.Add(character, 1);
- }
- }
- foreach (var count in counts)
- {
- Console.WriteLine($"{count.Key} -> {count.Value}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement