Loading...

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

gina78 avatar gina78 4 Точки

07. Legendary Farming

Здравейте, колеги много се измъчих с тая задача някой може ли да помогне

07. Legendary Farming 

You’ve beaten all the content and the last thing left to accomplish is own a legendary item. However, it’s a tedious process and requires quite a bit of farming. Anyway, you are not too pretentious – any legendary will do.
 The possible items are:

  • Shadowmourne – requires 250 Shards;
  • Valanyr – requires 250 Fragments;
  • Dragonwrath – requires 250 Motes;

Shards, Fragments and Motes are the key materials, all else is junk. You will be given lines of input, such as
2 motes 3 ores 15 stones. Keep track of the key materials - the first that reaches the 250 mark wins the race. At that point, print the corresponding legendary obtained. Then, print the remaining shards, fragments, motes, ordered by quantity in descending order, then by name in ascending order, each on a new line. Finally, print the collected junk items, in alphabetical order.

Input

  • Each line of input is in format {quantity} {material} {quantity} {material} … {quantity} {material}

Output

  • On the first line, print the obtained item in format {Legendary item} obtained!
  • On the next three lines, print the remaining key materials in descending order by quantity
    • All materials are printed in format {material}: {quantity}
    • If two key materials have the same quantity, print them in alphabetical order
  • On the final several lines, print the junk items in alphabetical order
    • All materials are printed in format {material}: {quantity}
    • All output should be lowercase, except the first letter of the legendary

Examples

Input

Output

3 Motes 5 stones 5 Shards

6 leathers 255 fragments 7 Shards

Valanyr obtained!

fragments: 5

shards: 5

motes: 3

leathers: 6

stones: 5

123 silver 6 shards 8 shards 5 motes

9 fangs 75 motes 103 MOTES 8 Shards

86 Motes 7 stones 19 silver

Dragonwrath obtained!

shards: 22

motes: 19

fragments: 0

fangs: 9

silver: 123

 

това ми е кода 

<?php

/*
  Shadowmourne – requires 250 Shards;
  Valanyr – requires 250 Fragments;
  Dragonwrath – requires 250 Motes;
 */
$newArr = []; 
$name = "";
$sum = 0;

$shadowmourne = false;
$valanyr = false;
$dragonwrath = false;
$prize = "";
while ($shadowmourne == false && $valanyr == false && $dragonwrath == false) {
$arr = explode(" ", readline());
    for ($i = 0; $i < count($arr); $i += 2) {
        $name = strtolower($arr[$i + 1]);
        $sum = $arr[$i];
        if (!key_exists($name, $newArr)) {
            $newArr[$name] = $sum;
            if ($newArr[$name] !== "fragments") {
                $name = "fragments"; 
                $newArr[$name] = 0;
            } elseif ($newArr[$name] !== "shards") {
                $name = "shards"; 
                $newArr[$name] = 0;
            }elseif ($newArr[$name] !== "motes") {
                $name = "motes"; 
                $newArr[$name] = 0;
            }
        }
        else if (key_exists($name, $newArr)) {
            if ($newArr["fragments"] >= 250) {
            $valanyr = true;
            $prize = "Valanyr";
            $newArr["fragments"] -= 250;
            break;
        } else if ($newArr["shards"] >= 250) {
            $shadowmourne = true;
            $prize = "Shadowmourne";
            $newArr["shards"] -= 250;
            break;
        } else if ($newArr["motes"] >= 250) {
            $dragonwrath = true;
            $prize = "Dragonwrath";
            $newArr["motes"] -= 250;
            break;
        }
            $newArr[$name] += $sum;
        } 
    }
}
echo"$prize obtained!" . PHP_EOL; 
foreach ($newArr as $key => $val) {
    echo "$key: $val".PHP_EOL;
}

Тагове:
0
PHP Fundamentals 09/07/2019 15:56:46
willystyle avatar willystyle 2472 Точки
<?php
$keyMaterials = ["fragments" => 0, "motes" => 0, "shards" => 0];
$junkMaterials = [];
$prizeMap = ["shards" => "Shadowmourne", "fragments" => "Valanyr", "motes" => "Dragonwrath"];
$win = false;
while (!$win) {
    $arr = explode(" ", readline());
    for ($i = 0; $i < count($arr); $i += 2) {
        $sum = intval($arr[$i]);
        $nameMaterial = strtolower($arr[$i + 1]);
        if (key_exists($nameMaterial, $keyMaterials)) {
            $keyMaterials[$nameMaterial] += $sum;
            if ($keyMaterials[$nameMaterial] >= 250) {
                $keyMaterials[$nameMaterial] -= 250;
                $win = true;
                break;
            }
            continue;
        }
        if (!key_exists($nameMaterial, $junkMaterials)) {
            $junkMaterials[$nameMaterial] = 0;
        }
        $junkMaterials[$nameMaterial] += $sum;
    }
}
echo "{$prizeMap[$nameMaterial]} obtained!" . PHP_EOL;
arsort($keyMaterials);
foreach ($keyMaterials as $key => $val) {
    echo "$key: $val" . PHP_EOL;
}
ksort($junkMaterials);
foreach ($junkMaterials as $key => $val) {
    echo "$key: $val" . PHP_EOL;
}

 

1
gina78 avatar gina78 4 Точки

Благодаря ти много

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