# Calculating the number of instances a word is inputed and the number of instances of an object that word is linked to

So for this program the user is supposed to input two numbers on the first line separated by a space. The first number is the number of contestants in a competition we will call it M and the second number is the total amount of votes received N.

The user then inputs M lines consisting of a name and a country Then the user inputs N lines consisting of only a name

The goal of the program is to calculate the name that got the most number of votes as well as the country and print them out. If there is a tie for the most number of votes you print out the lexicographically smallest.

I have what I believe to be as working solution to this problem but when I try to submit my code I get wrong answer. Even though it works for all given test cases and test cases that I created on my own.

Example I/O: Input: 4 5 Ramanujan India Torricelli Italy Gauss Germany Lagrange Italy Ramanujan Torricelli Torricelli Ramanujan Lagrange

Output: Italy Ramanujan

my code:

``````public class ChefOfTheYear2 {

static PrintWriter pw = new PrintWriter(System.out, true);

public static void main(String[] args) throws NumberFormatException, IOException {
ArrayList<String> allC = new ArrayList<String>();
ArrayList<C> allC2 = new ArrayList<C>();

String[] input = new String[2];
Map<String, C> countries = new HashMap<String, C>();
Map<String, Contestant> people = new HashMap<String, Contestant>();
String[] keys = new String[Integer.parseInt(contestants[0])];
//add countries  being voted on into allC array
for(int i=0; i<Integer.parseInt(contestants[0]); i++)
{
if(!allC.contains(input[1]))
people.put(input[0], new Contestant(input[0], input[1]));
keys[i]=input[0];
}
// Creates arrayList of Country objects
for(int i=0; i<allC.size(); i++)
{
}
//creates hashmap of country objects and the key is the contestants name who is from that country
for(int i=0; i<Integer.parseInt(contestants[0]); i++)
{
countries.put(keys[i],allC2.get(search(people.get(keys[i]).getCountry(), allC)));
}

{
}

//Sorts the arrays
C[] updatedC = countries.values().toArray(new C[countries.size()]);
Arrays.sort(updatedC, new CountryComparator());
Contestant[] updatedPeople = people.values().toArray(new Contestant[people.size()]);
Arrays.sort(updatedPeople, new peopleComparator());
pw.println(updatedC[updatedC.length-1].getName());
pw.println(updatedPeople[updatedPeople.length-1].getName());
pw.println("Bam! DOne! "+ System.currentTimeMillis());

}

public static int search(String key, ArrayList<String> a)
{
for(int i=0; i<a.size(); i++)
{
if(a.get(i).equalsIgnoreCase(key))
return i;
}
return -1;
}

}

class C
{
String name="";
public C(String name)
{
this.name=name;
}
public String getName()
{
return name;

}
{
}
{
}

}

class Contestant
{
String country="";
String name="";
public Contestant(String name, String country)
{
this.name=name;
this.country=country;
}
public String getCountry() {
return country;
}

public String getName()
{
return name;

}
{
}
{
}

}

class CountryComparator implements Comparator<C>
{

@Override
public int compare(C a, C b) {
return avote>bvote ?1 : bvote>avote ?-1 : b.getName().compareTo(a.getName());
}

}
class peopleComparator implements Comparator<Contestant>
{

@Override
public int compare(Contestant o1, Contestant o2) {
 Can you provide more info here, why your code is rejected? Maybe you have some special requirements for the assignment? Does submission system provides any feedback? I tried and I got the same output as you. – alex Jan 3 at 15:32 just to be sure, you submitted it with or without this line: `pw.println("Bam! DOne! "+ System.currentTimeMillis());` ? – tb- Jan 7 at 21:12