如何查詢一個字串中重複次數最多的字元,返回這個字元的個數和字元
阿新 • • 發佈:2019-01-29
{
string str ="1232143546534135164161";
foreach(char c in str)
{
Check(c);
}
char maxChar = Char.MinValue;
int maxValue =0;
foreach(KeyValuePair<char, int> kvp in sd)
{
Console.WriteLine("Dictionary has a Key : {0} and Value: {1} ", kvp.Key, kvp.Value);
if(kvp.Value > maxValue)
{
maxValue = kvp.Value;
maxChar = kvp.Key;
}
}
Console.WriteLine("Max char is {0}, times is {1}.", maxChar, maxValue);
Console.ReadLine();
}
string str ="1232143546534135164161";
foreach(char c in str)
{
Check(c);
}
char maxChar = Char.MinValue;
int maxValue =0;
foreach(KeyValuePair<char, int> kvp in sd)
{
Console.WriteLine("Dictionary has a Key : {0} and Value: {1}
if(kvp.Value > maxValue)
{
maxValue = kvp.Value;
maxChar = kvp.Key;
}
}
Console.WriteLine("Max char is {0}, times is {1}.", maxChar, maxValue);
Console.ReadLine();
}