Potresti creare un array di interi in cui inserisci le occorrenze di tutti i caratteri che incontri man mano