Guest User

Untitled

a guest
May 9th, 2016
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.87 KB | None | 0 0
  1. import java.util.*;
  2. import java.util.regex.Matcher;
  3. import java.util.regex.Pattern;
  4. import java.util.stream.Collectors;
  5.  
  6. /**
  7.  * Created by vb on 8.5.2016 г..
  8.  */
  9. public class problem4 {
  10.     public static void main(String[] args) {
  11.         Scanner console = new Scanner(System.in);
  12.         Pattern valid = Pattern.compile("([A-Za-z]+);(\\d+);(\\d+.*\\d*);([A-Za-z]+)");
  13.         HashMap<String,TreeMap<String,double[]>> employeeData=new HashMap<>();
  14.         while (true){
  15.             String line = console.nextLine();
  16.             if (line.equals("Pishi kuf i da si hodim")){
  17.                 break;
  18.             }
  19.             Matcher match = valid.matcher(line);
  20.             if (match.find()){
  21.                 if (!employeeData.containsKey(match.group(4))){
  22.                     employeeData.put(match.group(4),new TreeMap<>());
  23.                 }
  24.            if (!employeeData.get(match.group(4)).containsKey(match.group(1))){
  25.                employeeData.get(match.group(4)).put(match.group(1),new double[2]);
  26.                employeeData.get(match.group(4)).get(match.group(1))[0]=Double.parseDouble(match.group(2));
  27.                employeeData.get(match.group(4)).get(match.group(1))[1]=(Double.parseDouble(match.group(2))*Double.parseDouble(match.group(3)))/24;
  28.            }
  29.             }
  30.         }
  31.         int c =0;
  32.     ArrayList<Map.Entry<String,TreeMap>> sorted=new ArrayList<>();
  33.         for (Map.Entry e :  employeeData.entrySet().stream().sorted((k1, k2) ->
  34.                 Double.compare( calculateMountly(k1.getValue()), calculateMountly(k2.getValue()))).collect(Collectors.toSet())) {
  35.             sorted.add(e);
  36.         }
  37. //
  38.         for (Map.Entry<String, TreeMap> stringTreeMapEntry : sorted) {
  39.             System.out.println("Team - "+stringTreeMapEntry.getKey());
  40.             ArrayList<Map.Entry<String,double[]>> sortedem=new ArrayList<>();
  41.             TreeMap<String,double[]> map = stringTreeMapEntry.getValue();
  42.             for (Map.Entry<String,double[]> s : map.entrySet()) {
  43.                 sortedem.add(s);
  44.  
  45.             }
  46.            sortedem.sort((o1, o2) -> {
  47.                double totalO1 = o1.getValue()[0];
  48.                double totalO2 = o2.getValue()[0];
  49.                int cmp = Double.compare(totalO2, totalO1);
  50.                if (cmp == 0) {
  51.                    cmp =Double.compare(o1.getValue()[1], o1.getValue()[1]);
  52.                }
  53.  
  54.                return cmp;
  55.            });
  56.             for( Map.Entry<String,double[]> me : sortedem) {
  57.                 System.out.printf("$$$%s - %.0f - %.6f",me.getKey(),(me.getValue()[0]),me.getValue()[1]);
  58.                 System.out.println();
  59.  
  60.             }
  61.  
  62.         }
  63.  
  64.     }
  65.     private static double calculateMountly(TreeMap<String,double[]> en) {
  66.         double money = 0;
  67.         for (String s : en.keySet()) {
  68.             money += en.get(s)[1] / 30;
  69.         }
  70.    return  money;
  71.     }
  72.  
  73.  
  74.  
  75. }
Advertisement
Add Comment
Please, Sign In to add comment