Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- public class measurement {
- public static void main(String[] args) throws IOException {
- Scanner sc = new Scanner(new File("measurement.in"));
- //Scanner sc = new Scanner(System.in);
- PrintWriter pw = new PrintWriter(new FileWriter("measurement.out"));
- int n = sc.nextInt();
- int changes = 0;
- String dis = "";
- sc.nextLine();
- String[] log = new String[n];
- TreeMap<String,Integer> off = new TreeMap<String,Integer>();
- off.put("Bessie", 7);
- off.put("Elsie", 7);
- off.put("Mildred", 7);
- for(int x = 0; x<n; x++){
- log[x] = sc.nextLine();
- }
- //System.out.println(Arrays.toString(log));
- Arrays.sort(log);
- int count = 0;
- for(int day = 1; day<=100; day++){
- if(count < n && String.valueOf(day).equals(log[count].substring(0, log[count].indexOf(" ")))){
- String[] data = log[count].split(" ");
- String cow = data[1];
- int value = 0;
- if(data[2].charAt(0) == '+')
- value = Integer.parseInt(data[2].substring(1));
- else
- value = Integer.parseInt(data[2]);
- //System.out.println(value);
- off.put(cow, off.get(cow)+value);
- count++;
- }
- //System.out.println(off);
- String disp = displayed(off);
- if(!disp.equals(dis)){
- System.out.println(disp);
- changes++;
- }
- dis = disp;
- }
- //pw.println(changes);
- pw.println(changes);
- pw.close();
- sc.close();
- }
- public static String displayed(TreeMap<String,Integer> off){
- String dis = "";
- int max = -100;
- for(String s : off.keySet()){
- max = Math.max(off.get(s), max);
- }
- for(String s : off.keySet()){
- if(off.get(s) == max)
- dis+=s;
- }
- return dis;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement