Advertisement
deyanmalinov

05. Robotics

May 20th, 2019
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.04 KB | None | 0 0
  1. package DPM;
  2.  
  3. import java.util.ArrayDeque;
  4. import java.util.Deque;
  5. import java.util.Scanner;
  6.  
  7. public class Main {
  8.     public static void main(String[] args){
  9.         Scanner scan = new Scanner(System.in);
  10.         String [] line = scan.nextLine().split(";");
  11.         String [] robots = new String[line.length];
  12.         int [] procTime = new int[line.length];
  13.         int [] workTime = new int[line.length];
  14.  
  15.         for (int i = 0; i < line.length; i++) {
  16.             String[] temp = line[i].split("-");
  17.             robots[i] = temp[0];
  18.             procTime[i] = Integer.parseInt(temp[1]);
  19.  
  20.         }
  21.         String startTime = scan.nextLine();
  22.  
  23.  
  24.  
  25.         Deque<String> products = new ArrayDeque<>();
  26.  
  27.         String end = scan.nextLine();
  28.  
  29.         while (!end.equals("End")){
  30.             products.offer(end);
  31.             end = scan.nextLine();
  32.         }
  33.         String [] timeData = startTime.split(":");
  34.         int hours = Integer.parseInt(timeData[0]);
  35.         int min = Integer.parseInt(timeData[1]);
  36.         int sec = Integer.parseInt(timeData[2]);
  37.         int begSec = hours * 3600 + min * 60 + sec;
  38.  
  39.         while (!products.isEmpty()) {
  40.             begSec++;
  41.             String prod = products.poll();
  42.  
  43.             boolean isAssigned = false;
  44.             for (int i = 0; i < robots.length; i++) {
  45.                 if (workTime[i] == 0 && !isAssigned) {
  46.                     workTime[i] = procTime[i];
  47.                     isAssigned = true;
  48.                     printRobotData(robots[i], prod, begSec);
  49.                 }
  50.                 if (workTime[i] > 0) {
  51.                     workTime[i]--;
  52.                 }
  53.  
  54.             }
  55.             if (!isAssigned){
  56.                 products.offer(prod);
  57.             }
  58.         }
  59.  
  60.     }
  61.  
  62.     private static void printRobotData(String robot, String prod, int begSec) {
  63.         long s = begSec % 60;
  64.         long m = (begSec / 60)% 60;
  65.         long h = (begSec / (60*60)) %24;
  66.  
  67.         System.out.println(robot + " - "+ prod + " "+ String.format("[%02d:%02d:%02d]", h, m,s));
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement