Advertisement
Guest User

Untitled

a guest
Nov 11th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. <?php
  2.  
  3. $arr = explode(' ', readline());
  4.  
  5. $p = 0;
  6.  
  7. $arr2 = [];
  8.  
  9. for ($i = 0; $i < count($arr); $i++)
  10. {
  11. for ($j = $i + 1; $j < count($arr); $j++)
  12. {
  13. $p++;
  14. $arr2[$p][] = $arr[$i];
  15. if ($arr[$j] > $arr[$i])
  16. {
  17. array_push($arr2[$p], $arr[$j]);
  18. $currentNumber = $arr[$j];
  19. for ($k = $j + 1; $k < count($arr); $k++)
  20. {
  21. if ($currentNumber < $arr[$k])
  22. {
  23. array_push($arr2[$p], $arr[$k]);
  24. $currentNumber = $arr[$k];
  25. }
  26. }
  27. for ($r = $j + 2; $r < count($arr); $r++)
  28. {
  29. if ($arr[$r] > $arr[$j])
  30. {
  31. $p++;
  32. $arr2[$p][] = $arr[$i];
  33. array_push($arr2[$p], $arr[$j]);
  34. array_push($arr2[$p], $arr[$r]);
  35. $number = $arr[$r];
  36. for ($u = $r + 1; $u < count($arr); $u++)
  37. {
  38. if ($number < $arr[$u])
  39. {
  40. array_push($arr2[$p], $arr[$u]);
  41. $number = $arr[$u];
  42. }
  43. }
  44. }
  45. }
  46. }
  47. }
  48. }
  49.  
  50. uksort($arr2, function ($key1, $key2) use ($arr2)
  51. {
  52. if (count($arr2[$key1]) == count($arr2[$key2]))
  53. {
  54. return $key1 <=> $key2;
  55. }
  56. else
  57. {
  58. return count($arr2[$key2]) <=> count($arr2[$key1]);
  59. }
  60. });
  61.  
  62. if (count($arr2) > 1)
  63. {
  64. echo implode(' ', array_shift($arr2));
  65. }
  66. else
  67. {
  68. echo implode(' ', $arr);
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement