SHARE
TWEET

Untitled

kristina111 Feb 10th, 2017 144 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. $inputArr = explode(' ', trim(fgets(STDIN)));
  3. $inputArr = array_filter($inputArr, function ($value){return $value!=='';});
  4. $arrLength = count($inputArr);
  5. $longestSeq = null;
  6. $currentSeq = [$inputArr[0]];
  7.  
  8. for($i=1, $k = 0; $i<$arrLength; $i++){
  9.     if($inputArr[$i] > $currentSeq[$k]) {
  10.         $currentSeq[] = $inputArr[$i];
  11.         $k++;
  12.         continue;
  13.     }
  14.  
  15.     if(count($currentSeq) > count($longestSeq)){
  16.         $longestSeq = $currentSeq;
  17.     }
  18.     $currentSeq = [$inputArr[$i]];
  19.     $k = 0;
  20. }
  21.  
  22. if(count($currentSeq) > count($longestSeq)){
  23.     $longestSeq = $currentSeq;
  24. }
  25. $longestSeq = trim(implode(' ', $longestSeq));
  26. echo $longestSeq;
  27.  
  28. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top