Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.nio.file.OpenOption;
- import java.util.*;
- public class test {
- public static void main(String[] args) throws IOException {
- BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
- LinkedHashMap<String, List<OpponentInfo>> gameData = new LinkedHashMap<>();
- while (true) {
- String line = bf.readLine();
- if ("osu!".equals(line)) {
- break;
- }
- String[] tokens = line.split("[\\s<\\->]+");
- // Change to object Long?!
- Long playerOneScore = Long.valueOf(tokens[0]);
- String playerOneName = tokens[1];
- // Deleted all variables for forming a object Opponent info
- String playerTwoName = tokens[2];
- Long playerTwoScore = Long.valueOf(tokens[3]);
- // fill the map without finding the winner and looser
- if(!gameData.containsKey(playerOneName)){
- gameData.put(playerOneName, new ArrayList<>());
- }
- gameData.get(playerOneName)
- .add(new OpponentInfo(playerTwoName, playerOneScore - playerTwoScore));
- if(!gameData.containsKey(playerTwoName)){
- gameData.put(playerTwoName, new ArrayList<>());
- }
- gameData.get(playerTwoName)
- .add(new OpponentInfo(playerOneName, playerTwoScore - playerOneScore));
- }
- gameData.entrySet().stream()
- .sorted((a, b) -> sortByTotalScore(a.getValue(), b.getValue()))
- .forEach(p -> printAll(p));
- }
- private static void printAll(Map.Entry<String, List<OpponentInfo>> p) {
- System.out.printf("%s - (%d)\n", p.getKey(), p.getValue().stream().mapToLong(OpponentInfo::getMatchScore).sum());
- for (OpponentInfo op : p.getValue()) {
- System.out.printf("* %s <-> %d\n", op.getOpponentName(), op.getMatchScore());
- }
- }
- private static int sortByTotalScore(List<OpponentInfo> a, List<OpponentInfo> b) {
- long playerOneScore = a.stream().mapToLong(OpponentInfo::getMatchScore).sum();
- long playerTwoScore = b.stream().mapToLong(OpponentInfo::getMatchScore).sum();
- return Long.compare(playerTwoScore, playerOneScore);
- }
- public static class OpponentInfo {
- public String opponentName;
- public long matchScore;
- public OpponentInfo() {
- }
- public OpponentInfo(String opponentName, long matchScore) {
- this.opponentName = opponentName;
- this.matchScore = matchScore;
- }
- public String getOpponentName() {
- return opponentName;
- }
- public void setOpponentName(String opponentName) {
- this.opponentName = opponentName;
- }
- public long getMatchScore() {
- return matchScore;
- }
- public void setMatchScore(long matchScore) {
- this.matchScore = matchScore;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement