Advertisement
Guest User

Lendo do terminal

a guest
Dec 5th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.58 KB | None | 0 0
  1. <?php
  2.     $f = fopen( 'php://stdin', 'r' );
  3.  
  4.     while( $line = fgets( $f ) ) {
  5.         $entrada = str_split($line, 1);
  6.         array_pop($entrada); // remove o ENTER
  7.         $somador = 0;
  8.         $tamanho = count($entrada)-1;
  9.        
  10.         for ($i = 0; $i < count($entrada); $i++)
  11.         {
  12.             if ($i > 0) {
  13.             if (($entrada[$i-1] > $entrada[$i]) && ($entrada[$tamanho-2] <= $entrada[$tamanho])) {
  14.                 $somador += 1;
  15.             }
  16.             }
  17.         }
  18.        
  19.         echo $somador;
  20.         echo "\n";
  21.     }
  22.    
  23.     fclose( $f );
  24. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement