private static void GetMostChar()
{
string str = "aaabbbccceeefff111144444";
Dictionary<char, int> chardict = new Dictionary<char, int>();
int maxcount = 0;
char x = 'a';
foreach (char a in str)
{
if (chardict.ContainsKey(a))
{
chardict[a] += 1;
if (maxcount < chardict[a])
{
maxcount = chardict[a];
x = a;
}
}
else
{
chardict.Add(a, 1);
}
}
Console.WriteLine(x.ToString());
Console.WriteLine(maxcount);
}
c#找出字符串中出现最多的字符及次数
最新推荐文章于 2023-01-11 21:45:19 发布