Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function getMaxAndUnset(&$arr)
- {
- $max = max($arr);
- if (($key = array_search($max, $arr)) !== false) {
- unset($arr[$key]);
- }
- return $max;
- }
- function getResult($n)
- {
- $arr = range(1, $n);
- $arr_length = count($arr);
- $last_player = "";
- for ($i = 0; $i < $arr_length; $i++)
- {
- if (count($arr) > 1) {
- $max_value = getMaxAndUnset($arr);
- $max_value2 = getMaxAndUnset($arr);
- $last_player = ($last_player == 'Kitty' ? 'Katty' : 'Kitty');
- if ($max_value - $max_value2) {
- array_push($arr, ($max_value - $max_value2));
- }
- }
- if ($last_player == "") $last_player = "Kitty";
- }
- if (max($arr) % 3 == 1) $last_player = "Kitty";
- if (max($arr) % 3 == 2) $last_player = "Katty";
- return $last_player;
- }
- $handle = fopen ("php://stdin","r");
- fscanf($handle,"%d",$T);
- for($a0 = 0; $a0 < $T; $a0++){
- fscanf($handle,"%d",$n);
- echo getResult($n) . "\n";
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement