【ロボット暴走】STEP: 2 RPG (paizaランク B 相当) 解答例 – PHP編【クラス・構造体メニュー】
【クラス・構造体メニュー】 > 【ロボット暴走】STEP: 2 RPG (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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
<?php class hero{ public $l; public $h; public $a; public $d; public $s; public $c; public $f; public function __construct($l , $h , $a , $d , $s , $c , $f){ $this->l = $l; $this->h = $h; $this->a = $a; $this->d = $d; $this->s = $s; $this->c = $c; $this->f = $f; } public function levelup($h , $a , $d , $s , $c , $f){ $this->l ++; $this->h += $h; $this->a += $a; $this->d += $d; $this->s += $s; $this->c += $c; $this->f += $f; } public function muscle_training($h , $a){ $this->h += $h; $this->a += $a; } public function running($d , $s){ $this->d += $d; $this->s += $s; } public function study($c){ $this->c += $c; } public function pray($f){ $this->f += $f; } } $input = explode(" ",trim(fgets(STDIN))); $n = $input[0]; $k = $input[1]; $heros = array(); for($i = 1;$i <= $n;$i++){ $stats = explode(" ",trim(fgets(STDIN))); $l = $stats[0]; $h = $stats[1]; $a = $stats[2]; $d = $stats[3]; $s = $stats[4]; $c = $stats[5]; $f = $stats[6]; $heros[$i] = new hero($l, $h , $a , $d , $s , $c , $f); } //print_r($heros); for($i = 0;$i < $k;$i++){ $test = explode(" ",trim(fgets(STDIN))); $num = $test[0]; $event = $test[1]; if($event == "levelup"){ $h = $test[2]; $a = $test[3]; $d = $test[4]; $s = $test[5]; $c = $test[6]; $f = $test[7]; $heros[$num]->levelup($h , $a , $d , $s , $c , $f); } elseif($event == "muscle_training"){ $h = $test[2]; $a = $test[3]; $heros[$num]->muscle_training($h , $a); } elseif($event == "running"){ $d = $test[2]; $s = $test[3]; $heros[$num]->running($d , $s); } elseif($event == "study"){ $c = $test[2]; $heros[$num]->study($c); } elseif($event == "pray"){ $f = $test[2]; $heros[$num]->pray($f); } } //print_r($heros); foreach($heros as $value){ echo $value->l." ".$value->h." ".$value->a." ".$value->d." ".$value->s." ".$value->c." ".$value->f."\n"; } ?> |
