JAVA
java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import java.util.Scanner;
import java.util.Map;
import java.util.HashMap;
import java.lang.Integer;
import java.lang.Character;
public class Program
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String request = sc.next();
int numberOfVotes = request.length();
HashMap<Character,Integer> result = new HashMap<Character,Integer>();
// Count votes
for(int i = 0; i < request.length(); i++) {
char candidate = request.charAt(i);
if( result.containsKey(candidate) ){
int temp = result.get(candidate);
temp++;
result.put(candidate, temp);
} else {
result.put(candidate, 1);
}
}
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run