【ロボット暴走】STEP: 1 出口のない迷路 (paizaランク B 相当) 解答例 – PHP編【クラス・構造体メニュー】
【クラス・構造体メニュー】 > 【ロボット暴走】STEP: 1 出口のない迷路 (paizaランク B 相当)
※リンク先へ移動する為には「paiza」へのログインが必要です。
解答例
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
<?php class spell{ public $word; public $one; public $two; public function __construct($word , $one ,$two){ $this->word = $word; $this->one = $one; $this->two = $two; } } $input = explode(" ",trim(fgets(STDIN))); $n = $input[0]; $k = $input[1]; $s = $input[2]; for($i = 1;$i <= $n;$i++){ $test = explode(" ",trim(fgets(STDIN))); $w = $test[0]; $a = $test[1]; $b = $test[2]; $array[$i] = new spell($w, $a ,$b); } $spell[] = $array[$s]->word; $point = $s; for($i = 0;$i < $k;$i++){ $load = trim(fgets(STDIN)); if($load == 1){ array_push($spell , $array[$array[$point]->one]->word); $point = $array[$point]->one; } elseif($load == 2){ array_push($spell , $array[$array[$point]->two]->word); $point = $array[$point]->two; } } //print_r($spell); echo implode($spell); ?> |
