Advertisement
Aborigenius

RepetitionInDictionary

Jul 9th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.79 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace LetterRepetiton
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Dictionary<char, int> letters = new Dictionary<char, int>();
  14.  
  15.             char[] inputChars = Console.ReadLine().ToArray();
  16.             for (int i = 0; i < inputChars.Length; i++)
  17.             {
  18.                 if (!letters.ContainsKey(inputChars[i]))
  19.                 {
  20.                     letters.Add(inputChars[i], 0);
  21.                 }
  22.                 letters[inputChars[i]]++;
  23.             }
  24.             foreach (var item in letters.Keys)
  25.             {
  26.                 Console.WriteLine($"{item} -> {letters[item]}");
  27.             }
  28.         }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement