Advertisement
NarekNavoyan

15-1

Dec 19th, 2021
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.42 KB | None | 0 0
  1. string sentence = Console.ReadLine();
  2. List<char> chars = new List<char>();
  3. List<int> counts = new List<int>();
  4.  
  5. foreach (char c in sentence)
  6. {
  7.     if (!chars.Contains(c))
  8.     {
  9.         chars.Add(c);
  10.         counts.Add(1);
  11.     }
  12.     else
  13.     {
  14.         int index = chars.IndexOf(c);
  15.         counts[index]++;
  16.     }
  17. }
  18.  
  19. for (int i = 0; i < chars.Count; i++)
  20. {
  21.     Console.WriteLine($"[{chars[i]}] - {counts[i]}");
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement