Created
July 12, 2013 20:48
-
-
Save boxysean/5987725 to your computer and use it in GitHub Desktop.
Solution to UVA 10420
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The for-loop at line 29 looks great but what exactly is going on in "(Map.Entry<String, ...)"?