Дана строка S. нужно вывести все буквы, которые встречаются в ней, и их количество -
Ответы
Ответ:
Python3:
s = input("Введите строку: ")
letters = {}
for char in s:
if char in letters:
letters[char] += 1
else:
letters[char] = 1
for char, count in letters.items():
print(char, count)
C#
using System;
using System.Collections.Generic;
namespace CountCharsInLine
{
internal class Program
{
public static void Main(string[] args)
{
Console.Write("Введите строку: ");
string S = Console.ReadLine();
var dic = new Dictionary<char, int>();
foreach (char ch in S)
{
var lowerch = char.ToLower(ch);
if (!dic.ContainsKey(lowerch))
{
dic.Add(lowerch, 1);
}
else
{
dic[lowerch]++;
}
}
foreach (char ch in dic.Keys)
{
Console.WriteLine($"{ch} : {dic[ch]}");
}
}
}
}