Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace _2._1.Count_Chars_in_a_String
- {
- class Program
- {
- static void Main()
- {
- string word = Console.ReadLine();
- Dictionary<char, int> histogram = new Dictionary<char, int>();
- foreach (var currentChar in word)
- {
- if (currentChar != ' ')
- {
- if (!histogram.ContainsKey(currentChar))
- {
- // histogram.Add(currentChar, 0);
- histogram[currentChar] = 0;
- }
- histogram[currentChar]++;
- }
- }
- foreach (var item in histogram)
- {
- Console.WriteLine($"{item.Key} -> {item.Value}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment