Skip to content

Instantly share code, notes, and snippets.

@boxysean
Created July 12, 2013 20:48
Show Gist options
  • Save boxysean/5987725 to your computer and use it in GitHub Desktop.
Save boxysean/5987725 to your computer and use it in GitHub Desktop.
Solution to UVA 10420
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Map;
import java.util.TreeMap;
public class Main {
public static void main(String args[]) throws Exception {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(in.readLine());
TreeMap<String, Integer> map = new TreeMap<String, Integer>();
for (int count = 0; count < N; count++) {
String line = in.readLine();
String split[] = line.split(" ");
String country = split[0];
int countryCount = 0;
if (map.containsKey(country)) {
countryCount = map.get(country);
}
map.put(country, countryCount+1);
}
for (Map.Entry<String, Integer> e : map.entrySet()) {
System.out.printf("%s %d\n", e.getKey(), e.getValue());
}
}
}
@benjaminxie
Copy link

The for-loop at line 29 looks great but what exactly is going on in "(Map.Entry<String, ...)"?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment