【構造体の更新 】STEP: 2 構造体の検索 (paizaランク C 相当) 解答例 – PHP編【クラス・構造体メニュー】
【クラス・構造体メニュー】 > 【構造体の更新 】STEP: 2 構造体の検索 (paizaランク C 相当)
※リンク先へ移動する為には「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 |
<?php class Account{ public $newname; public $newold; public $newbirth; public $newstate; public function __construct($name , $old , $birth , $state){ $this->newname = $name; $this->newold = $old; $this->newbirth = $birth; $this->newstate = $state; } } $n = trim(fgets(STDIN)); for($i = 0;$i < $n;$i++){ $test = explode(" ",trim(fgets(STDIN))); $add = new Account($test[0] , $test[1] , $test[2] , $test[3]); $new[$i] = $add; } $target_old = trim(fgets(STDIN)); //print_r($new); for($i = 0;$i < $n;$i++){ if($new[$i]->newold == $target_old){ echo $new[$i]->newname."\n"; } } ?> |
