Loading...

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

Petyvel avatar Petyvel 2 Точки

legendary farming

моля за малко помощ при кода. Ако не е във while ми дава unreachable code, ако е вътре не работи както трябва.

https://pastebin.com/AVC8gg0F

това е условието

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
o 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
o All materials are printed in format {material}: {quantity}
o The output should be lowercase, except for the first letter of the legendary

Тагове:
0
Fundamentals Module
zjelev avatar zjelev 8 Точки

Ламбда изразa на рeд 101 се пише x=>x.Value, а не kvp => junkMat.Values. Не знам за какво са ти тези continue...

Ето моето решение:

using System;

using System.Collections.Generic;

using System.Linq;

namespace _03LegendaryFarming

{

    class Program

    {

        static void Main(string[] args)

        {

            var keyMat = new Dictionary<stringint>();

            keyMat["shards"] = 0;

            keyMat["fragments"] = 0;

            keyMat["motes"] = 0;

            var junkMat = new SortedDictionary<stringint>();

            bool hasToBreak = false;

            string legendaryItem = String.Empty;

 

            while (!hasToBreak)

            {

                string[] input = Console.ReadLine().ToLower().Split(' ');

 

                for (int i = 0i < input.Lengthi += 2)

                {

                    int quantity = int.Parse(input[i]);

                    string material = input[i + 1];

 

                    if (keyMat.ContainsKey(material))

                    {

                        keyMat[material] += quantity;                        

                        if (keyMat[material] >= 250)

                        {

                            if (material == "shards")

                            {

                                legendaryItem = "Shadowmourne";

                            }

                            else if (material == "fragments")

                            {

                                legendaryItem = "Valanyr";

                            }

                            else

                            {

                                legendaryItem = "Dragonwrath";

                            }

                            keyMat[material] -= 250;

                            hasToBreak = true;

                            Console.WriteLine($"{legendaryItem} obtained!");

                            break;

                        }

                    }

                    else

                    {

                        if (!junkMat.ContainsKey(material))

                        {

                            junkMat.Add(material0);

                        }

                        junkMat[material] += quantity;

                    }

                }

            }

 

            keyMat = keyMat.OrderByDescending(x => x.Value) .ThenBy(x => x.Key) .ToDictionary(a => a.Keya => a.Value);

            foreach (var item in keyMat)

            {

                Console.WriteLine($"{item.Key}: {item.Value}");

            }

 

            foreach (var item in junkMat)

            {

                Console.WriteLine($"{item.Key}: {item.Value}");

            }

        }

    }

}

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