the following code is compiling and running fine in my system for the problem CVOTE. however, it fails to compile in codeshef. Can someone please explain why??
import java.util.*;
public class Main {
public static void main (String[] args){
Scanner scn = new Scanner(System.in);
int n=scn.nextInt();
int m=scn.nextInt();
HashMap hm1 = new HashMap(); //chef and votes
HashMap hm2 = new HashMap(); // country and votes
HashMap hm3 = new HashMap(); // input- chef and country
for(int i=0;i<n;i++){
String key = scn.next();
String value=scn.next();
String temp=scn.nextLine();
hm3.put(key, value);
}
Set set = hm3.keySet();
Iterator hmitr = set.iterator();
while(hmitr.hasNext()){
Object key1= hmitr.next();
Object value1= hm3.get(key1);
hm1.put(key1,0);
hm2.put(value1,0);
}
for(int i=0;i<m;i++){
String candidate= scn.nextLine();
hm1.put(candidate,(int)hm1.get(candidate)+1);
hm2.put(hm3.get(candidate),(int) hm2.get(hm3.get(candidate))+1);
}
String bestcountry="zzzzzzzzzz";
int maxvotes=0;
set=hm2.keySet();
hmitr=set.iterator();
while(hmitr.hasNext()){
String country= (String)hmitr.next();
if((int)hm2.get(country)>maxvotes){
maxvotes=(int)hm2.get(country);
bestcountry=country;
}
if((int)hm2.get(country)==maxvotes){
bestcountry= (bestcountry.compareTo(country))<0 ?bestcountry:country;
}
}
System.out.println(bestcountry);
String bestcandidate="zzzzzzzzzz";
maxvotes=0;
set=hm1.keySet();
hmitr=set.iterator();
while(hmitr.hasNext()){
String candidate= (String)hmitr.next();
if((int)hm1.get(candidate)>maxvotes){
maxvotes=(int)hm1.get(candidate);
bestcandidate=candidate;
}
if((int)hm1.get(candidate)==maxvotes){
bestcandidate= (bestcandidate.compareTo(candidate))<0 ?bestcandidate:candidate;
}
}
System.out.println(bestcandidate);
}
}
Error shown by codeshef-
Main.java:32: inconvertible types found : java.lang.Object required: int hm1.put(candidate,(int)hm1.get(candidate)+1); ^ Main.java:32: operator + cannot be applied to ,int hm1.put(candidate,(int)hm1.get(candidate)+1); ^ Main.java:33: inconvertible types found : java.lang.Object required: int hm2.put(hm3.get(candidate),(int) hm2.get(hm3.get(candidate))+1); ^ Main.java:33: operator + cannot be applied to ,int hm2.put(hm3.get(candidate),(int) hm2.get(hm3.get(candidate))+1); ^ Main.java:42: inconvertible types found : java.lang.Object required: int if((int)hm2.get(country)>maxvotes){ ^ Main.java:43: inconvertible types found : java.lang.Object required: int maxvotes=(int)hm2.get(country); ^ Main.java:46: inconvertible types found : java.lang.Object required: int if((int)hm2.get(country)==maxvotes){ ^ Main.java:61: inconvertible types found : java.lang.Object required: int if((int)hm1.get(candidate)>maxvotes){ ^ Main.java:62: inconvertible types found : java.lang.Object required: int maxvotes=(int)hm1.get(candidate); ^ Main.java:65: inconvertible types found : java.lang.Object required: int if((int)hm1.get(candidate)==maxvotes){ ^ Note: Main.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. 10 errors
Thanx in advance!!!