Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- import java.util.stream.Collectors;
- /**
- * Created by vb on 8.5.2016 г..
- */
- public class problem4 {
- public static void main(String[] args) {
- Scanner console = new Scanner(System.in);
- Pattern valid = Pattern.compile("([A-Za-z]+);(\\d+);(\\d+.*\\d*);([A-Za-z]+)");
- HashMap<String,TreeMap<String,double[]>> employeeData=new HashMap<>();
- while (true){
- String line = console.nextLine();
- if (line.equals("Pishi kuf i da si hodim")){
- break;
- }
- Matcher match = valid.matcher(line);
- if (match.find()){
- if (!employeeData.containsKey(match.group(4))){
- employeeData.put(match.group(4),new TreeMap<>());
- }
- if (!employeeData.get(match.group(4)).containsKey(match.group(1))){
- employeeData.get(match.group(4)).put(match.group(1),new double[2]);
- employeeData.get(match.group(4)).get(match.group(1))[0]=Double.parseDouble(match.group(2));
- employeeData.get(match.group(4)).get(match.group(1))[1]=(Double.parseDouble(match.group(2))*Double.parseDouble(match.group(3)))/24;
- }
- }
- }
- int c =0;
- ArrayList<Map.Entry<String,TreeMap>> sorted=new ArrayList<>();
- for (Map.Entry e : employeeData.entrySet().stream().sorted((k1, k2) ->
- Double.compare( calculateMountly(k1.getValue()), calculateMountly(k2.getValue()))).collect(Collectors.toSet())) {
- sorted.add(e);
- }
- //
- for (Map.Entry<String, TreeMap> stringTreeMapEntry : sorted) {
- System.out.println("Team - "+stringTreeMapEntry.getKey());
- ArrayList<Map.Entry<String,double[]>> sortedem=new ArrayList<>();
- TreeMap<String,double[]> map = stringTreeMapEntry.getValue();
- for (Map.Entry<String,double[]> s : map.entrySet()) {
- sortedem.add(s);
- }
- sortedem.sort((o1, o2) -> {
- double totalO1 = o1.getValue()[0];
- double totalO2 = o2.getValue()[0];
- int cmp = Double.compare(totalO2, totalO1);
- if (cmp == 0) {
- cmp =Double.compare(o1.getValue()[1], o1.getValue()[1]);
- }
- return cmp;
- });
- for( Map.Entry<String,double[]> me : sortedem) {
- System.out.printf("$$$%s - %.0f - %.6f",me.getKey(),(me.getValue()[0]),me.getValue()[1]);
- System.out.println();
- }
- }
- }
- private static double calculateMountly(TreeMap<String,double[]> en) {
- double money = 0;
- for (String s : en.keySet()) {
- money += en.get(s)[1] / 30;
- }
- return money;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment