Loading...

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

danail2003 avatar danail2003 27 Точки

Cooking Factory

Здравейте, получавам 90/100, а не мога да си открия грешката. Ако може помощ.

 

 

The George`s Cooking factory got another order. But this time you are tasked to bake
the best Bread for a special party.

Until you receive a command "Bake it!" you will be receiving strings, the batches of bread. Each string is an array of numbers, split by "#". Each element is a bread and the number represent its quality.

You should select the batch with the highest total quality of bread.

If there are several batches with same total quality select the batch with the greater average quality.

If there are several batches with same total quality and average quality, take the one with the fewest elements (length).

Input / Constraints

  • Until you receive a command "Bake it!" you will be receiving strings, the batches of bread. Each string is an array of numbers, split by "#". Each element is a bread and the number represent its quality.
  • Each batch will have from 1 to 10 elements.
  • Bread quality is an integer in the range [-100, 100].

Output

  • After you receive the last command "Bake It!" you should print the following message:

"Best Batch quality: {bestTotalQuality}"

"{bread batch, joined by space}"

 Examples

Input

Output

Comments

5#4#10#-2

10#5#2#3#2

Bake It!

Best Batch quality: 22

10 5 2 3 2

We receive 2 batches, but the second is printed, because its total quality is better.

Input

Output

Comments

5#3#2

10#2#-2#1#-1

4#2#1

Bake It!

Best Batch quality: 10

5 3 2

We receive 3 sequences. Both 1 and 2 have same total quality -> 10, but the first is printed, because its has better average quality 3.(333).

 

 

using System;

namespace Cooking_Factory
{
    class Program
    {
        static void Main(string[] args)
        {         
            string command = Console.ReadLine();
            double highestQuality = 0;
            double maxValue = int.MinValue;
            int maxElements = int.MinValue;
            double maxAverage = int.MinValue;
            string[] numbers = new string[10];

            while(command != "Bake It!")
            {
                string[] convert = command.Split("#");

                for (int i = 0; i < convert.Length; i++)
                {
                    int number = int.Parse(convert[i]);
                    highestQuality += number;                  
                }

                double averageQuality = highestQuality / convert.Length;

                if (highestQuality > maxValue)
                {
                    maxValue = highestQuality;
                    numbers = convert;
                }

                if (averageQuality > maxAverage)
                {
                    if (maxValue == highestQuality)
                    {
                        maxAverage = averageQuality;
                        numbers = convert;
                    }
                }

                if (maxValue == highestQuality && averageQuality == maxAverage && convert.Length > maxElements)
                {
                    maxElements = convert.Length;
                    numbers = convert;
                }

                highestQuality = 0;
                command = Console.ReadLine();
            }

            int total = 0;

            for (int i = 0; i < numbers.Length; i++)
            {
                int number = int.Parse(numbers[i]);
                total += number;
            }

            Console.WriteLine($"Best Batch quality: {total}");
            Console.WriteLine(string.Join(" ", numbers));
        }
    }
}

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