Advertisement
silvana1303

count chars in string

Jul 7th, 2020
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.88 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5.  
  6. namespace Order_By_Age
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             string[] word = Console.ReadLine().Split();
  13.  
  14.             Dictionary<char, int> output = new Dictionary<char, int>();
  15.  
  16.             for (int i = 0; i < word.Length; i++)
  17.             {
  18.                 string some = word[i];
  19.  
  20.                 foreach (char item in some)
  21.                 {
  22.                     if (output.ContainsKey(item))
  23.                     {
  24.                         output[item]++;
  25.                     }
  26.                     else
  27.                     {
  28.                         output[item] = 1;
  29.                     }
  30.                 }
  31.             }
  32.  
  33.             foreach (var num in output)
  34.                 Console.WriteLine($"{num.Key} -> {num.Value}");
  35.  
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement