Advertisement
philRG

CoC d'entraînement à PHP

Apr 21st, 2021
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.57 KB | None | 0 0
  1. <?php
  2.  
  3. //fscanf(STDIN, "%d", $n);
  4.  
  5. $snakes = array();
  6. $snakes[0] = '>-rrrrr';
  7. $snakes[1] = 'rrrrr-<';
  8. $snakes[2] = '-<rrrrr';
  9. $n = 3;
  10.  
  11. var_dump($snakes);
  12.  
  13. $happy_snakes_count = 0;
  14.  
  15. for ($i = 0; $i < $n; $i++) {
  16.     $snake = $snakes[$i];
  17.     $len_snake = strlen($snake);
  18. //    $snake = stream_get_line($line, 25 + 1, "\n");
  19.     $right_tail = strpos($snake, "-<") == strlen($snake) - 2;
  20.     $left_tail = strpos($snake, ">-") == 0;
  21.     if ($right_tail || $left_tail)
  22.         $happy_snakes_count += 1;
  23. }
  24. $pct = round(100 * $happy_snakes_count / $n);
  25. print("$pct%")
  26. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement