static void Main(string[] args)
{
Dictionary<char, int> dic = new Dictionary<char, int>();
Console.WriteLine("请输入一句话");
string str = Console.ReadLine();
for (int i = 0; i < str.Length; i++)
{
char ch = str[i];
if (dic.ContainsKey(ch))
{
dic[ch]++;
}
else
{
dic.Add(ch, 1);
}
}
foreach (KeyValuePair<char, int> temp in dic)
{
Console.WriteLine(temp.Key + ":" + temp.Value);
}
} |