Loading...

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

Th3D4rkStar avatar Th3D4rkStar 21 Точки

03. Legendary Farming

Колеги, от два дни я мъча задачата, гледах и други постове във форума, но каквото и да правя Judge ми дава 80/100. Някой ако може някакви насоки да ми даде, ще съм много благодарен. Задачата съм я писал не по най-простия начин, но все пак. Ето кода и условието.


https://pastebin.com/yEmgHGvr

 

3. Legendary Farming

You’ve done all the work and the last thing left to accomplish is to own a legendary item. However, it’s a tedious process and it requires quite a bit of farming. Anyway, you are not too pretentious - any legendary item 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 and everything else is junk. You will be given lines of input, in the format:

2 motes 3 ores 15 stones

Keep track of the key materials - the first one that reaches the 250 mark, wins the race. At that point you have to print that the corresponding legendary item is 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 comes in the following format: {quantity} {material} {quantity} {material} … {quantity} {material}

Output

  • On the first line, print the obtained item in the format: {Legendary item} obtained!
  • On the next three lines, print the remaining key materials in descending order by 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}
    • The output should be lowercase, except for 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

0
Module: C# Advanced
ivailogeimara avatar ivailogeimara 37 Точки
Best Answer

Гърми защото задаваш int value = 0, което е валиден брой и после проверяваш

if (key != string.Empty && value != 0)

което няма да влезе при примерен input motes 0. След това ще прескочи всеки следващ input докато не получи нещо различно от 0. Т.е. при input:

fragments 30 shards 0 motes 10 shards 20 wood 0 motes 0 gold 30

ще се запише:

fragments 30
shards 10
shards 20
wood 30

което е равно на:

fragments 30
shards 30
wood 30

Така, че си смени преди for цикъла:

int value = 0;

на:

int value = int.MinValue;

и

if (key != string.Empty && value != 0)

на:

if (key != string.Empty && value != int.MinValue)

и в края на if-а:

key = string.Empty; value = 0;

на:

key = string.Empty; value = int.MinValue;

Иначе ето едно по-добро решение:

using System;
using System.Collections.Generic;
using System.Linq;

namespace _03._LegendaryFarming
{
    class Program
    {
        static void Main(string[] args)
        {
            string legendaryItem = String.Empty;
            Dictionary<string, int> materials = new Dictionary<string, int>();
            materials.Add("motes", 0);
            materials.Add("shards", 0);
            materials.Add("fragments", 0);
            Dictionary<string, int> junk = new Dictionary<string, int>();

            while (materials["motes"] < 250 && materials["fragments"] < 250 && materials["shards"] < 250)
            {
                string input = Console.ReadLine().ToLower();
                string[] inputTokens = input.Split(" ");
                for (int i = 0; i < inputTokens.Length; i+=2)
                {
                    int quantity = int.Parse(inputTokens[i]);
                    string material = inputTokens[i + 1];

                    switch (material)
                    {
                        case "shards":
                        case "fragments":
                        case "motes":
                            materials[material] += quantity;
                            break;
                        default:
                            if (!junk.ContainsKey(material))
                                junk.Add(material, 0);
                            junk[material] += quantity;
                            break;
                    }

                    if (materials["shards"] >= 250 || materials["fragments"] >= 250 || materials["motes"] >= 250)
                        break;
                }
            }

            if (materials["shards"] >= 250)
            {
                legendaryItem = "Shadowmourne";
                materials["shards"] -= 250;
            }
            else if (materials["fragments"] >= 250)
            {
                legendaryItem = "Valanyr";
                materials["fragments"] -= 250;
            }
            else
            {
                legendaryItem = "Dragonwrath";
                materials["motes"] -= 250;
            }
            
            Console.WriteLine($"{legendaryItem} obtained!");

            foreach (var item in materials.OrderByDescending(entry => entry.Value).ThenBy(entry => entry.Key))
            {
                Console.WriteLine($"{item.Key}: {item.Value}");
            }

            foreach (var item in junk.OrderBy(entry => entry.Key))
            {
                Console.WriteLine($"{item.Key}: {item.Value}");
            }

        }
    }
}

 

0
12/03/2020 01:00:54
Th3D4rkStar avatar Th3D4rkStar 21 Точки

Много благодаря, колега! Хич не съм го съобразил.

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