Advertisement
Guest User

11. Robotics

a guest
May 23rd, 2018
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.25 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4. import java.time.LocalTime;
  5. import java.time.format.DateTimeFormatter;
  6. import java.util.ArrayDeque;
  7.  
  8. /**
  9.  * Created by IntelliJ IDEA.
  10.  * User: LAPD
  11.  * Date: 22.5.2018 г.
  12.  * Time: 08:57 ч.
  13.  */
  14. public class _11Robotics {
  15.     public static void main(String[] args) throws IOException {
  16.         BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
  17.  
  18.         String[] robotsData = bufferedReader.readLine()
  19.                 .split(";");
  20.  
  21.         int robotsCount = robotsData.length;
  22.  
  23.         String[] robotsName = new String[robotsCount];
  24.         int[] robotsDefaultProcessTime = new int[robotsCount];
  25.         int[] robotsCurrentProgress = new int[robotsCount];
  26.  
  27.         String[] robotData;
  28.         for (int i = 0; i < robotsCount; i++) {
  29.             robotData = robotsData[i]
  30.                     .split("-");
  31.  
  32.             robotsName[i] = robotData[0];
  33.             robotsDefaultProcessTime[i] = Integer
  34.                     .parseInt(robotData[1]);
  35.             robotsCurrentProgress[i] = Integer
  36.                     .parseInt(robotData[1]);
  37.         }
  38.  
  39.         String[] timeData = bufferedReader.readLine()
  40.                 .split("(:0)+|:+");
  41.  
  42.         int hours = Integer.parseInt(timeData[0]);
  43.         int mins = Integer.parseInt(timeData[1]);
  44.         int secs = Integer.parseInt(timeData[2]);
  45.  
  46.         ArrayDeque<String> productsQueue = new ArrayDeque<>();
  47.  
  48.         String productName;
  49.         while (!"End".equals(productName = bufferedReader.readLine())) {
  50.             productsQueue.add(productName);
  51.         }
  52.  
  53.         StringBuilder result = new StringBuilder();
  54.  
  55.         boolean hasFreeRobot;
  56.         int freeRobotIndex;
  57.  
  58.         while (productsQueue.size() > 0) {
  59.             secs++;
  60.  
  61.             hasFreeRobot = false;
  62.             freeRobotIndex = -1;
  63.  
  64.             for (int i = 0; i < robotsCount; i++) {
  65.                 robotsCurrentProgress[i]++;
  66.  
  67.                 if (!hasFreeRobot
  68.                         && robotsCurrentProgress[i] >= robotsDefaultProcessTime[i]) {
  69.                     hasFreeRobot = true;
  70.                     freeRobotIndex = i;
  71.                 }
  72.             }
  73.  
  74.             if (hasFreeRobot) {
  75.                 robotsCurrentProgress[freeRobotIndex] = 0;
  76.  
  77.                 while (secs >= 60) {
  78.                     mins++;
  79.                     secs -= 60;
  80.                 }
  81.  
  82.                 while (mins >= 60) {
  83.                     hours++;
  84.                     mins -= 60;
  85.                 }
  86.  
  87.                 result.append(robotsName[freeRobotIndex])
  88.                         .append(" - ")
  89.                         .append(productsQueue.remove())
  90.                         .append(" [")
  91.                         .append(String.format("%02d", hours))
  92.                         .append(":")
  93.                         .append(String.format("%02d", mins))
  94.                         .append(":")
  95.                         .append(String.format("%02d", secs))
  96.                         .append("]")
  97.                         .append(System.lineSeparator());
  98.  
  99.             } else {
  100.                 productsQueue.add(productsQueue.remove());
  101.             }
  102.         }
  103.  
  104.         System.out.println(result);
  105.     }
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement