Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static int findMaxMT(String[] lines) throws InterruptedException {
- List numbers = new ArrayList();
- int size = lines.length;
- int[] results = new int[size];
- int max = Integer.MIN_VALUE;
- for (int i = size - 1; i >=0; i--) {
- int fi = i;
- Thread t = new Thread(new Runnable() {
- @Override
- public void run() {
- List num = new ArrayList();
- int currentMax = Integer.MIN_VALUE;
- for (String s : lines[fi].split("\s")) {
- num.add(Integer.parseInt(s));
- }
- for (int n : num) {
- try {
- Thread.sleep(1);
- if (n > currentMax) {
- currentMax = n;
- }
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- results[fi] = currentMax;
- }
- });
- t.start();
- t.join();
- }
- for (int n : results) {
- if (n > max) {
- max = n;
- }
- }
- return max;
- }
- }
- String[] lines = {
- "706 575 855 882 595 778 477 602 147 467 693 793 120 384 256 866 548 367 910 848",
- "206 232 632 315 743 823 620 111 279 548 210 393 791 815 519 768 168 484 780 705",
- "709 127 900 171 189 590 563 317 600 975 892 296 166 353 863 312 399 872 964 591",
- "302 869 679 157 419 485 325 290 739 149 407 648 688 474 311 177 318 611 348 557",
- "559 283 171 352 698 759 384 822 598 410 802 293 962 859 812 153 436 392 869 167"};
Add Comment
Please, Sign In to add comment