Advertisement
kristina111

Untitled

Feb 10th, 2017
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.67 KB | None | 0 0
  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. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement