emodev

Untitled

Dec 9th, 2018
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.21 KB | None | 0 0
  1. import java.awt.*;
  2. import java.io.BufferedReader;
  3. import java.io.IOException;
  4. import java.io.InputStreamReader;
  5. import java.util.*;
  6. import java.util.List;
  7.  
  8. public class RoboticsClass {
  9.     public static void main(String[] args) throws IOException {
  10.         BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  11.         String[] robotsToken = reader.readLine().split(";");
  12.         List<Robot> robots = new ArrayList<>();
  13.  
  14.         for (int i = 0; i < robotsToken.length; i++) {
  15.             String[] robotToken = robotsToken[i].split("-");
  16.             Robot robot = new Robot(robotToken[0], Integer.parseInt(robotToken[1]));
  17.             robots.add(robot);
  18.         }
  19.  
  20.         String[] time = reader.readLine().split(":");
  21.         long hour = Integer.parseInt(time[0]) * 3600;
  22.         long minute = Integer.parseInt(time[1]) * 60;
  23.         long seconds = Integer.parseInt(time[2]);
  24.         long allSeconds = hour + minute + seconds;
  25.  
  26.         Deque<String> products = new ArrayDeque<>();
  27.  
  28.         while (true) {
  29.             String product = reader.readLine();
  30.             if (product.equals("End")) {
  31.                 break;
  32.             }
  33.             products.offer(product);
  34.         }
  35.  
  36.         while (!products.isEmpty()) {
  37.             allSeconds++;
  38.             for (int i = 0; i < robots.size(); i++) {
  39.                 Robot robot = robots.get(i);
  40.                 if (robot.getRobotsCounter() > 0){
  41.                     robot.manipulateCounter();
  42.                 }
  43.             }
  44.             String currentProduct = products.poll();
  45.             boolean isTaken = false;
  46.  
  47.             for (int i = 0; i < robots.size(); i++) {
  48.                 Robot robot = robots.get(i);
  49.                 if (robot.getRobotsCounter() == 0){
  50.                     robot.setRobotsCounter(robot.getProcessTime());
  51.                     isTaken = true;
  52.                     System.out.printf("%s - %s [%s]%n",robot.getName()
  53.                             ,currentProduct,robot.convertSeconds(allSeconds));
  54.                     break;
  55.                 }
  56.             }
  57.             if (!isTaken){
  58.                 products.offer(currentProduct);
  59.             }
  60.         }
  61.  
  62.  
  63.     }
  64.  
  65.  
  66. }
  67.  
  68. class Robot {
  69.     private String name;
  70.     private int processTime;
  71.     private int robotsCounter;
  72.  
  73.     public Robot(String name, int processTime) {
  74.         this.name = name;
  75.         this.processTime = processTime;
  76.     }
  77.  
  78.     public int getRobotsCounter() {
  79.         return robotsCounter;
  80.     }
  81.  
  82.     public void setRobotsCounter(int robotsCounter) {
  83.         this.robotsCounter = robotsCounter;
  84.     }
  85.  
  86.     public String getName() {
  87.         return name;
  88.     }
  89.  
  90.     public void setName(String name) {
  91.         this.name = name;
  92.     }
  93.  
  94.     public int getProcessTime() {
  95.         return processTime;
  96.     }
  97.  
  98.     public void setProcessTime(int processTime) {
  99.         this.processTime = processTime;
  100.     }
  101.  
  102.     public void manipulateCounter(){
  103.         this.robotsCounter--;
  104.     }
  105.  
  106.     public String convertSeconds(long sec) {
  107.         long seconds = sec % 60;
  108.         long minutes = (sec / 60) % 60;
  109.         long hours = (sec / 3600) % 24;
  110.         return String.format("%02d:%02d:%02d", hours, minutes, seconds);
  111.     }
  112. }
Add Comment
Please, Sign In to add comment