RGAlex

ТаяСроботите

May 24th, 2021
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.57 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class Robotics {
  4.  
  5.     public static void main(String[] args) {
  6.  
  7.         Scanner scan = new Scanner(System.in);
  8.         String[] robotsInfo = scan.nextLine().split(";");
  9.         Robots[] robots = new Robots[robotsInfo.length];
  10.         for (int i = 0; i < robotsInfo.length; i++) {
  11.             String[] robotData = robotsInfo[i].split("-");
  12.             Robots data = new Robots(robotData[0], Integer.parseInt(robotData[1]), 0);
  13.             robots[i] = data;
  14.         }
  15.         String[] time = scan.nextLine().split(":");
  16.         int startTime = (Integer.parseInt(time[0]) * 3600) + (Integer.parseInt(time[1]) * 60) + Integer.parseInt(time[2]);
  17.  
  18.         ArrayDeque<String> productsQueue = new ArrayDeque<>();
  19.         String productsInfo;
  20.         while (!"End".equals(productsInfo = scan.nextLine())) {
  21.             productsQueue.offer(productsInfo);
  22.         }
  23.  
  24.         while (!productsQueue.isEmpty()) {
  25.  
  26.             startTime++;
  27.             String product = productsQueue.poll();
  28.             boolean productIsNotAccepted = true;
  29.  
  30.             for (Robots robot : robots) {
  31.                 if (robot.getWorkingTime() > 0) {
  32.                     robot.setWorkingTime(robot.getWorkingTime() - 1);
  33.                 }
  34.                 if (robot.getWorkingTime() == 0 && productIsNotAccepted) {
  35.                     robot.setWorkingTime(robot.getProcessTime());
  36.                     System.out.println(robotInfo(startTime, robot.getName(), product));
  37.                     productIsNotAccepted = false;
  38.                 }
  39.             }
  40.             if (productIsNotAccepted) {
  41.                 productsQueue.offer(product);
  42.             }
  43.         }
  44.     }
  45.  
  46.     private static String robotInfo(int startTime, String name, String product) {
  47.         return String.format("%s - %s [%02d:%02d:%02d]", name, product, (startTime / 3600) % 24
  48.                 , (startTime / 60) % 60, startTime % 60);
  49.     }
  50.  
  51.     public static class Robots {
  52.         String name;
  53.         int processTime;
  54.         int workingTime;
  55.  
  56.         public String getName() {
  57.             return name;
  58.         }
  59.  
  60.         public int getProcessTime() {
  61.             return processTime;
  62.         }
  63.  
  64.         public int getWorkingTime() {
  65.             return workingTime;
  66.         }
  67.  
  68.         public void setWorkingTime(int workingTime) {
  69.             this.workingTime = workingTime;
  70.         }
  71.  
  72.         public Robots(String name, int processTime, int workingTime) {
  73.             this.name = name;
  74.             this.processTime = processTime;
  75.             this.workingTime = workingTime;
  76.         }
  77.     }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment