#include <stdio.h>
#include <stdlib.h>
int main() {
char string[100];
char tabela[256];
// Limpa a tabela.
for (int i = 0; i < 256; i++) {
tabela[i] = 0;
}
// Lê a frase do usuário.
printf ("\nEscreva um texto: \n"); fgets(string
, 100, stdin
);
// Monta a tabela de frequências.
for (int i = 0; i < tamanho; i++) {
char c = string[i];
// Ignora o espaço.
if (c == ' ') continue;
// Se for uma letra minúscula, troca por maiúscula.
if (c >= 'a' && c <= 'z') c = c - 'a' + 'A';
// Contabiliza na tabela.
tabela[c]++;
}
// Busca o índice de maior ocorrência na tabela.
int maior = 0;
char letra = '\0';
for (int i = 0; i < 256; i++) {
int t = tabela[i];
if (t > maior) {
maior = t;
letra = (char) i;
}
}
// Mostra o resultado.
printf("\nO caractere '%c' aparece %d vezes.\n", letra
, maior
);
// Fim.
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KCmludCBtYWluKCkgewogICAgY2hhciBzdHJpbmdbMTAwXTsKICAgIGNoYXIgdGFiZWxhWzI1Nl07CgogICAgLy8gTGltcGEgYSB0YWJlbGEuCiAgICBmb3IgKGludCBpID0gMDsgaSA8IDI1NjsgaSsrKSB7CiAgICAgICAgdGFiZWxhW2ldID0gMDsKICAgIH0KCiAgICAvLyBMw6ogYSBmcmFzZSBkbyB1c3XDoXJpby4KICAgIHByaW50ZiAoIlxuRXNjcmV2YSB1bSB0ZXh0bzogXG4iKTsKICAgIGZnZXRzKHN0cmluZywgMTAwLCBzdGRpbik7CiAgICBpbnQgdGFtYW5obyA9IHN0cmxlbihzdHJpbmcpOwoKICAgIC8vIE1vbnRhIGEgdGFiZWxhIGRlIGZyZXF1w6puY2lhcy4KICAgIGZvciAoaW50IGkgPSAwOyBpIDwgdGFtYW5obzsgaSsrKSB7CiAgICAgICAgY2hhciBjID0gc3RyaW5nW2ldOwoKICAgICAgICAvLyBJZ25vcmEgbyBlc3Bhw6dvLgogICAgICAgIGlmIChjID09ICcgJykgY29udG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