The output of a multithreaded system can be quite garbled, due to the interleaved execution that occurs. In this problem, we will model such a situation. Each thread's output will be described by a string. For example, the string "AB" would mean that after 1 time unit running, the thread would print an 'A'. After another time unit it would print a 'B'. After a third time unit, it would print an 'A' (wraps back to the beginning). You will be given a String[] describing the threads to be run. You will also be given a String[] containing the time slices each thread is given. Each element of slices will have the form "Thread# Time". Thread# is a 0-based index into threads. Time is how many units of time the thread in question will execute for. The elements of slices occur in the order they will be run. If a thread is executed, and then executed again at a later point, it starts where it left off (see examples for further clarification).
You will return a String containing the output in the order it occurred. For example, if
threads = {"AB","CD"}
slices = {"0 1","1 1","0 1","1 2"}
Then you would return "ACBDC". |