Click Here to go back to the homepage.

Stacking Cups Solution:


import java.util.*;

public class Kattis {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int cases = Integer.parseInt(sc.nextLine());
        HashMap<Integer, String> hm = new HashMap<>();
        List<Integer> list = new ArrayList<>();
        for(int i = 0; i < cases; i++){
            String[] s = sc.nextLine().split(" ");
            int curr;
            String color;
            try{
                curr = Integer.parseInt(s[0]) /2;
                color = s[1];
            }   catch (Exception e){
                curr = Integer.parseInt(s[1]);
                color = s[0];
            }
            list.add(curr);
            hm.put(curr, color);
        }
        Collections.sort(list);
        StringBuilder sb = new StringBuilder();
        for(int i : list)
            sb.append(hm.get(i) + "\n");
        System.out.println(sb);
    }
}