Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $array = preg_replace('/\s+/', '', explode(",", readline()));
- $regex = '/[^a-zA-Z\s]/';
- $regexInt = '/((?:-|\+|)\d+(?:\.*?\d+)*)/';
- $demons = [];
- for ($i = 0; $i < count($array); $i++) {
- $health = 0;
- $point = 0;
- $demon = $array[$i];
- $health = addHealth($regex, $health, $demon);
- $point = addPoints($regexInt, $point, $demon);
- $demons[$demon]['health'] = $health;
- $demons[$demon]['point'] = $point;
- }
- function addHealth($regex, $health, $demon)
- {
- $demon = preg_replace($regex, "", $demon);
- for ($i = 0; $i < strlen($demon); $i++) {
- $health += ord($demon[$i]);
- }
- return $health;
- }
- function addPoints($regexInt, $point, $demon)
- {
- preg_match_all($regexInt, $demon, $matches);
- for ($w = 0; $w < count($matches[0]); $w++) {
- $point += $matches[0][$w];
- }
- $str = $demon;
- $str = preg_replace("/[^\/\/*]/", "", $str);
- for ($d = 0; $d < strlen($str); $d++) {
- if ($str[$d] == "*") {
- $point *= 2;
- } elseif ($str[$d] == "/") {
- $point /= 2;
- }
- }
- return $point;
- }
- uksort($demons, function ($a, $b) use ($demons) {
- if ($demons[$a]['health'] === $demons[$b]['health']) return strcasecmp($a, $b);
- return $demons[$b]['health'] - $demons[$a]['health'];
- });
- foreach ($demons as $name => $value) {
- printf("$name - {$value['health']} health, %.2f damage" . PHP_EOL, $value['point']);
- }
- //print_r($demons);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement