Loading...

Във форума е въведено ограничение, което позволява на потребителите единствено да разглеждат публикуваните въпроси.

gina78 avatar gina78 4 Точки

Nether Realms

Здравейте тая задача само 80/100 я докарах, може ли малко помощ.Може ли да ми обясните къде греша в сорта или още някаде.

Благодаря.

това ми е кода   https://pastebin.com/0WM2Bvhs

Nether Realms

Mighty battle is coming. In the stormy nether realms, demons are fighting against each other for supremacy in a duel from which only one will survive.

Your job, however is not so exciting. You are assigned to sign in all the participants in the nether realm's mighty battle's demon book, which of course is sorted alphabetically.

A demon's name contains his health and his damage.

The sum of the asci codes of all characters (excluding numbers (0-9), arithmetic symbols ('+', '-', '*', '/') and delimiter dot ('.')) gives a demon's total health.

The sum of all numbers in his name forms his base damage. Note that you should consider the plus '+' and minus '-' signs (e.g. +10 is 10 and -10 is -10). However, there are some symbols ('*' and '/') that can further alter the base damage by multiplying or dividing it by 2 (e.g. in the name "m15*/c-5.0", the base damage is 15 + (-5.0) = 10 and then you need to multiply it by 2 (e.g. 10 * 2 = 20) and then divide it by 2 (e.g. 20 / 2 = 10)).

So, multiplication and division are applied only after all numbers are included in the calculation and in the order they appear in the name.

You will get all demons on a single line, separated by commas and zero or more blank spaces. Sort them in alphabetical order and print their names along their health and damage.

Input

The input will be read from the console. The input consists of a single line containing all demon names separated by commas and zero or more spaces in the format: "{demon name}, {demon name}, … {demon name}"

Output

Print all demons sorted by their name in ascending order, each on a separate line in the format:

"{demon name} - {health points} health, {damage points} damage"

Constraints

  • A demon's name will contain at least one character
  • A demon's name cannot contain blank spaces ' ' or commas ','
  • A floating point number will always have digits before and after its decimal separator
  • Number in a demon's name is considered everything that is a valid integer or floating point number (with dot '.' used as separator). For example, all these are valid numbers: '4', '+4', '-4', '3.5', '+3.5', '-3.5'

Examples

Input

Output

Comments

M3ph-0.5s-0.5t0.0**

M3ph-0.5s-0.5t0.0** - 524 health, 8.00 damage

M3ph-0.5s-0.5t0.0**:

Health = 'M' + 'p' + 'h' + 's' + 't' = 524 health.

Damage = (3 + (-0.5) + (-0.5) + 0.0) * 2 * 2 = 8 damage.

Input

Output

Comments

M3ph1st0**, Azazel

Azazel - 615 health, 0.00 damage

M3ph1st0** - 524 health, 16.00 damage

 

Azazel:

Health - 'A' + 'z' + 'a' + 'z' + 'e' + 'l' = 615 health. Damage - no digits = 0 damage.

 

M3ph1st0**:

Health - 'M' + 'p' + 'h' + 's' + 't' = 524 health.

Damage - (3 + 1 + 0) * 2 * 2 = 16 damage.

Gos/ho

Gos/ho - 512 health, 0.00 damage

 

Тагове:
0
PHP Fundamentals
willystyle avatar willystyle 2472 Точки

ctype_alpha не отговаря на условието на задачата

замени

$healthPoints = array_reduce(str_split($demon), function ($sum, $el) {
        ctype_alpha($el) ? $sum += ord($el) : false;
        return $sum;
    }, 0);

с

preg_match_all('/[^0-9\s.\/+*-]/', $demon, $charMach);
foreach ($charMach[0] as $demonChar) {
    $healthPoints += ord($demonChar);
}

 

0
gina78 avatar gina78 4 Точки

Благодаря

1
Можем ли да използваме бисквитки?
Ние използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Можете да се съгласите с всички или част от тях.
Назад
Функционални
Използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Използваме „сесийни“ бисквитки, за да Ви идентифицираме временно. Те се пазят само по време на активната употреба на услугите ни. След излизане от приложението, затваряне на браузъра или мобилното устройство, данните се трият. Използваме бисквитки, за да предоставим опцията „Запомни Ме“, която Ви позволява да използвате нашите услуги без да предоставяте потребителско име и парола. Допълнително е възможно да използваме бисквитки за да съхраняваме различни малки настройки, като избор на езика, позиции на менюта и персонализирано съдържание. Използваме бисквитки и за измерване на маркетинговите ни усилия.
Рекламни
Използваме бисквитки, за да измерваме маркетинг ефективността ни, броене на посещения, както и за проследяването дали дадено електронно писмо е било отворено.