Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.05 KB | None | 0 0
  1. <?php
  2. function getMaxAndUnset(&$arr)
  3. {
  4.     $max = max($arr);
  5.    
  6.     if (($key = array_search($max, $arr)) !== false) {
  7.             unset($arr[$key]);
  8.     }
  9.    
  10.     return $max;
  11. }
  12.  
  13. function getResult($n)
  14. {
  15.     $arr = range(1, $n);
  16.     $arr_length = count($arr);
  17.     $last_player = "";
  18.    
  19.     for ($i = 0; $i < $arr_length; $i++)
  20.     {
  21.         if (count($arr) > 1) {
  22.             $max_value = getMaxAndUnset($arr);
  23.             $max_value2 = getMaxAndUnset($arr);
  24.             $last_player = ($last_player == 'Kitty' ? 'Katty' : 'Kitty');
  25.             if ($max_value - $max_value2) {
  26.                 array_push($arr, ($max_value - $max_value2));
  27.             }
  28.         }
  29.        
  30.         if ($last_player == "") $last_player = "Kitty";
  31.     }
  32.    
  33.     if (max($arr) % 3 == 1) $last_player = "Kitty";
  34.     if (max($arr) % 3 == 2) $last_player = "Katty";
  35.    
  36.     return $last_player;
  37. }
  38.    
  39. $handle = fopen ("php://stdin","r");
  40. fscanf($handle,"%d",$T);
  41. for($a0 = 0; $a0 < $T; $a0++){
  42.     fscanf($handle,"%d",$n);
  43.     echo getResult($n) . "\n";
  44. }
  45. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement