Advertisement
Guest User

Untitled

a guest
Dec 16th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.*;
  3. public class measurement {
  4.  
  5. public static void main(String[] args) throws IOException {
  6. Scanner sc = new Scanner(new File("measurement.in"));
  7. //Scanner sc = new Scanner(System.in);
  8. PrintWriter pw = new PrintWriter(new FileWriter("measurement.out"));
  9. int n = sc.nextInt();
  10. int changes = 0;
  11. String dis = "";
  12. sc.nextLine();
  13. String[] log = new String[n];
  14. TreeMap<String,Integer> off = new TreeMap<String,Integer>();
  15. off.put("Bessie", 7);
  16. off.put("Elsie", 7);
  17. off.put("Mildred", 7);
  18.  
  19. for(int x = 0; x<n; x++){
  20. log[x] = sc.nextLine();
  21. }
  22. //System.out.println(Arrays.toString(log));
  23. Arrays.sort(log);
  24.  
  25. int count = 0;
  26. for(int day = 1; day<=100; day++){
  27. if(count < n && String.valueOf(day).equals(log[count].substring(0, log[count].indexOf(" ")))){
  28. String[] data = log[count].split(" ");
  29. String cow = data[1];
  30. int value = 0;
  31. if(data[2].charAt(0) == '+')
  32. value = Integer.parseInt(data[2].substring(1));
  33. else
  34. value = Integer.parseInt(data[2]);
  35. //System.out.println(value);
  36. off.put(cow, off.get(cow)+value);
  37. count++;
  38. }
  39. //System.out.println(off);
  40. String disp = displayed(off);
  41. if(!disp.equals(dis)){
  42. System.out.println(disp);
  43. changes++;
  44. }
  45. dis = disp;
  46. }
  47.  
  48. //pw.println(changes);
  49. pw.println(changes);
  50. pw.close();
  51. sc.close();
  52.  
  53. }
  54. public static String displayed(TreeMap<String,Integer> off){
  55. String dis = "";
  56. int max = -100;
  57. for(String s : off.keySet()){
  58. max = Math.max(off.get(s), max);
  59. }
  60. for(String s : off.keySet()){
  61. if(off.get(s) == max)
  62. dis+=s;
  63. }
  64. return dis;
  65. }
  66.  
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement