【構造体の更新 】FINAL問題 構造体の更新 (paizaランク C 相当) 解答例 – PHP編【クラス・構造体メニュー】
【クラス・構造体メニュー】 > 【構造体の更新 】FINAL問題 構造体の更新 (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 30 31 32 33 34 35 36 37 |
<?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; } } $input = explode(" ",trim(fgets(STDIN))); $n = $input[0]; $rewrite = $input[1]; 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; } for($i = 0;$i < $rewrite;$i++){ $test = explode(" ",trim(fgets(STDIN))); $num = $test[0] - 1; $rename = $test[1]; $new[$num]->newname = $rename; } //print_r($new); foreach($new as $value){ echo $value->newname." ".$value->newold." ".$value->newbirth." ".$value->newstate; echo "\n"; } ?> |