Mitrezzz

[АПС] Лаб 8: Бинарни пребарувачки дрва Black Friday

Dec 19th, 2018 (edited)
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.27 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class BlackFriday {
  4.     public static void main(String[] args) {
  5.        
  6.         Hashtable<Integer, Integer> table = new Hashtable<Integer, Integer>();
  7.         Scanner scanner = new Scanner(System.in);
  8.        
  9.         //read the number of clients
  10.         int N = Integer.parseInt(scanner.nextLine());
  11.         for (int i=0; i<N; ++i){
  12.            
  13.             //read a whole line
  14.             String s = scanner.nextLine();
  15.             String[] time = s.split("\\s+");
  16.             String[] inTime = time[0].split(":");
  17.            
  18.             //calculate the entering time
  19.             int in = Integer.parseInt(inTime[0])*60 + Integer.parseInt(inTime[1]);
  20.            
  21.             //calculate the exiting time
  22.             int out = in + Integer.parseInt(time[1]);
  23.            
  24.             //see if the timings are after closing at 23:59
  25.             if (in > 1439) in = 1439;
  26.             if (out > 1439) out = 1439;
  27.            
  28.             //for each minute, increment the value in the hash table
  29.             for (int j=in; j<=out; ++j){
  30.                 Integer minute = table.get(j);
  31.                 if (minute == null) table.put(j, 1);
  32.                 else{
  33.                     table.put(j, table.get(j) + 1);
  34.                 }
  35.             }
  36.         }
  37.        
  38.         int max = 0;
  39.        
  40.         //find the max counter in the values
  41.         for (Integer value : table.values()){
  42.             if (max < value) max = value;
  43.         }
  44.        
  45.         //print the max number of customers at a give point in time
  46.         System.out.println(max);
  47.        
  48.         scanner.close();
  49.     }
  50. }
Add Comment
Please, Sign In to add comment