Guest User

Untitled

a guest
Sep 20th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. public static int findMaxMT(String[] lines) throws InterruptedException {
  2.  
  3. List numbers = new ArrayList();
  4. int size = lines.length;
  5. int[] results = new int[size];
  6. int max = Integer.MIN_VALUE;
  7.  
  8. for (int i = size - 1; i >=0; i--) {
  9. int fi = i;
  10. Thread t = new Thread(new Runnable() {
  11. @Override
  12. public void run() {
  13.  
  14. List num = new ArrayList();
  15. int currentMax = Integer.MIN_VALUE;
  16.  
  17. for (String s : lines[fi].split("\s")) {
  18. num.add(Integer.parseInt(s));
  19. }
  20. for (int n : num) {
  21. try {
  22. Thread.sleep(1);
  23. if (n > currentMax) {
  24. currentMax = n;
  25. }
  26. } catch (InterruptedException e) {
  27. e.printStackTrace();
  28. }
  29. }
  30. results[fi] = currentMax;
  31. }
  32. });
  33. t.start();
  34. t.join();
  35. }
  36.  
  37. for (int n : results) {
  38. if (n > max) {
  39. max = n;
  40. }
  41. }
  42.  
  43. return max;
  44. }
  45. }
  46.  
  47. String[] lines = {
  48. "706 575 855 882 595 778 477 602 147 467 693 793 120 384 256 866 548 367 910 848",
  49. "206 232 632 315 743 823 620 111 279 548 210 393 791 815 519 768 168 484 780 705",
  50. "709 127 900 171 189 590 563 317 600 975 892 296 166 353 863 312 399 872 964 591",
  51. "302 869 679 157 419 485 325 290 739 149 407 648 688 474 311 177 318 611 348 557",
  52. "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