Advertisement
Qrist

DoublicateCharacter

Jun 17th, 2020
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.14 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace FindDuplicateCharacters
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             FindDoublicateCharactersCount.Find();
  11.         }
  12.     }
  13. }
  14.     static class FindDoublicateCharactersCount
  15.     {
  16.         public static void Find()
  17.         {
  18.             string line = Console.ReadLine();
  19.             char[] alonechar = line.ToCharArray();
  20.             Dictionary<char, int> dictionary = new Dictionary<char, int>();
  21.             foreach (var ch in alonechar)
  22.             {
  23.                 if (dictionary.ContainsKey(ch))
  24.                 {
  25.                     dictionary[ch] = dictionary[ch] + 1;
  26.                 }
  27.                 else
  28.                 {
  29.                     dictionary.Add(ch, 1);
  30.                 }
  31.             }
  32.             var keys = new HashSet<char>(dictionary.Keys);
  33.             foreach (var ch in keys)
  34.             {
  35.                 if (dictionary[ch] >= 1)
  36.                 {
  37.                     Console.WriteLine($"Character {ch} repeating {dictionary[ch]} times");
  38.                 }
  39.             }
  40.         }
  41.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement