char y[] = { 'a', 'b', 'a', 'c' };
int count[52] = {0};
for (int i = 0; i < (sizeof(x) / sizeof(char)); i++)
{
if (y[i] >= 65 && y[i] <= 90)
count[y[i] - 'A']++;
else if (y[i] >= 97 && y[i] <= 122)
count[(y[i] - 'a') + 26]++;
}
for (int i = 0; i < 52; i++)
{
if (i < 26 && count[i] > 0)
cout << char('A' + i) << ": " << count[i] << endl;
else if (i >= 26 && count[i] > 0)
cout << char('a' + i - 26) << ": " << count[i] << endl;
}
1
solved How to calculate number of repeated elements in a 1D array? [closed]