using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string str = "my program!";
Dictionary<char, int> dic = new Dictionary<char, int>();
for (int i = 0; i < str.Length; i++)
{
if (dic.ContainsKey(str[i]))
dic[str[i]]++;
else
dic[str[i]] = 1;
}
char max = str[0];
foreach (KeyValuePair<char, int> t in dic)
{
if (t.Value > dic[max])
{
max = t.Key;
}
}
Console.WriteLine(max + " " + dic[max]);
Console.ReadLine();
}
}
}
c#面试题:找出字符串中出现次数最多的字符及出现次数
最新推荐文章于 2026-08-21 13:24:52 发布
本文深入探讨了程序开发中数据结构与算法的重要作用,通过实例展示了如何有效地使用这些概念解决实际问题。

374

被折叠的 条评论
为什么被折叠?



