import java.util.*;
public class Demo {
public static void main(String[] args) {
Map<String, Integer> map = new HashMap<>();
String[] str = new String[26];
str[0] = "a-b 1:3";
str[1] = "a-c 2:3";
str[2] = "b-a 1:1";
str[3] = "c-a 0:1";
str[4] = "b-c 4:3";
str[5] = "c-b 2:2";
for (int i = 0; str[i] != null; i++) {
split(map, str[i]);
}
List<Map.Entry<String, Integer>> entries = new ArrayList<>(map.entrySet());
Collections.sort(entries, new Comparator<Map.Entry<String, Integer>>() {
@Override
public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
return o2.getValue().compareTo((o1.getValue()));
}
});
String s = "";
for (Map.Entry<String, Integer> mapping : entries) {
s += mapping.getKey() + ":" + mapping.getValue() + ",";
}
System.out.print(s.substring(0, s.lastIndexOf(',')));
}
private static void split(Map<String, Integer> map, String str) {
String team1 = str.substring(0, 1);
String team2 = str.substring(2, 3);
int score1 = str.substring(4, 5).getBytes()[0] - '0';
int score2 = str.substring(6, 7).getBytes()[0] - '0';
if (score1 > score2) {
score1 = 3;
score2 = 0;
} else if (score1 == score2) {
score1 = 1;
score2 = 1;
} else {
score1 = 0;
score2 = 3;
}
saveToMap(map, team1, score1);
saveToMap(map, team2, score2);
}
private static void saveToMap(Map<String, Integer> map, String team, int score) {
if (map.containsKey(team)) {
Integer i = map.get(team);
i += score;
map.put(team, i);
} else {
map.put(team, score);
}
}
}