Guest User

Untitled

a guest
Feb 28th, 2017
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.78 KB | None | 0 0
  1. <?php
  2. $inputArr = explode(" ", trim(fgets(STDIN)));
  3. $test = "2 1 1 2 3 3 2 2 2 1";
  4. //$inputArr = explode(" ", trim($test));
  5. //var_export($inputArr);
  6.  
  7. $inputArrCount = count($inputArr);
  8. $counter = 0;
  9. $element = '';
  10. //echo $inputArrCount." < count \n";
  11. for ($i = 0; $i < $inputArrCount; $i++) {
  12.   $currentElement = $inputArr[$i];
  13.   $localCounter = 1;
  14.   for ($n = $i + 1 ; $n < $inputArrCount; $n++) {
  15.     if ($inputArr[$n] == $currentElement)  {
  16.       $localCounter++;
  17.     } else {
  18.       break;
  19.     }
  20.     $i = $n;
  21.   }
  22.   //echo $currentElement . "-" . $localCounter ."\n";
  23.  
  24.   if ($localCounter > $counter) {
  25.       $counter = $localCounter;
  26.       $element = $currentElement;
  27.  
  28.   }
  29. }
  30. //echo $element . " e " . $counter;
  31. echo implode(" ",array_fill(0,$counter,$element));
Add Comment
Please, Sign In to add comment