For example, I have a string:
\"abbbbccd\"
b
has the most occurrences. When using C++, the easiest way to handle this is inser
Code:
class CharCount
{
public void CountCharacter()
{
int n;
Console.WriteLine("enter the no. of elements: ");
n = Convert.ToInt32(Console.ReadLine());
char[] chararr = new char[n];
Console.WriteLine("enter the elements in array: ");
for (int i = 0; i < n; i++)
{
chararr[i] = Convert.ToChar(Console.ReadLine());
}
Dictionary count = chararr.GroupBy(x => x).ToDictionary(g => g.Key, g => g.Count());
foreach(KeyValuePair key in count)
{
Console.WriteLine("Occurrence of {0}: {1}",key.Key,key.Value);
}
Console.ReadLine();
}
}