Loading...

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

petko.iliev avatar petko.iliev 2 Точки

Задача от -> C# Advanced Exam - 28 June 2020

Здравейте колеги

Judge ми дава 90/100 и не мога да открия грешката ако някой е решавал задачата моля за съдействие:

Код:https://pastebin.com/PVcsfaWG

Линк към Judge:https://judge.softuni.bg/Contests/Practice/Index/2444#0

Условие:

Bombs

 

Ezio still is learning to make bombs. With their help, he will save civilization. We should help Ezio to make his perfect bombs.

 

You will be given a two sequence of integers, representing bomb effects and bomb casings.

You need to start from the first bomb effect and try to mix it with the last bomb casing. If the sum of their values is equal to any of the materials in the table belowcreate the bomb corresponding to the value and remove the both bomb materials. Otherwise, just decrease the value of the bomb casing by 5. You need to stop combining when you have no more bomb effects or bomb casings, or you successfully filled the bomb pouch.

Bombs:

  • Datura Bombs: 40
  • Cherry Bombs: 60
  • Smoke Decoy Bombs: 120

To fill the bomb pouch, Ezio needs three of each of the bomb types.

Input

  • On the first line, you will receive the integers representing the bomb effects, separated by ", ".
  • On the second line, you will receive the integers representing the bomb casing, separated by ", ".

Output

  • On the first line of output – print one of these rows according whether Ezio succeeded fulfill the bomb pouch:
    • "Bene! You have successfully filled the bomb pouch!"
    • "You don't have enough materials to fill the bomb pouch."
  • On the second line - print all bomb effects left:
    • If there are no bomb effects: "Bomb Effects: empty"
    • If there are effects: "Bomb Effects: {bombEffect1}, {bombEffect2}, (…)"
  • On the third line - print all bomb casings left:
    • If there are no bomb casings: "Bomb Casings: empty"
    • If there are casings: "Bomb Casings: {bombCasing1}, {bombCasing2}, (…)"
  • Then, you need to print all created bombs and the count you have of them, ordered alphabetically:
    • "Cherry Bombs: {count}"
    • "Datura Bombs: {count}"
    • "Smoke Decoy Bombs: {count}"

Constraints

  • All of the given numbers will be valid integers in the range [0, 120].
  • Don't have situation with negative material.

 

Examples

Input

Output

5, 25, 50, 115

5, 15, 25, 35

You don't have enough materials to fill the bomb pouch.

Bomb Effects: empty

Bomb Casings: empty

Cherry Bombs: 1

Datura Bombs: 2

Smoke Decoy Bombs: 1

Comment

1) 5 + 35 = 40 -> Datura Bomb. Remove both.

2) 25 + 25 = 50 -> can't create bomb. Bomb casing should be decreased with 5 -> 20

3) 25 + 20 = 45 -> can't create bomb. Bomb casing should be decreased with 5 -> 15

4) 25 + 15 = 40 -> Datura Bomb. Remove both

 

Input

Output

30, 40, 5, 55, 50, 100, 110, 35, 40, 35, 100, 80

20, 25, 20, 5, 20, 20, 70, 5, 35, 0, 10

Bene! You have successfully filled the bomb pouch!

Bomb Effects: 100, 80

Bomb Casings: 20

Cherry Bombs: 3

Datura Bombs: 4

Smoke Decoy Bombs: 3

Comment

After creating a bomb with bomb effect 35 and bomb casing 25, have created 3 Cherry bombs, 4 Datura bombs, and 3 Smoke Decoy bombs. From all of the bomb types have 3 bombs and the program ends.

 

 

 

"Nothing is true; everything is permitted"

 

Тагове:
0
Module: C# Advanced
Axiomatik avatar Axiomatik 2422 Точки

The main-problem was that your solution was too long, memory-limit was 16.00MB and your solution needed over 16.60MB. This is what triggered the error. I also refactored your code to make it more compact.

Best,

Code(100%):

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

namespace _02._Bee
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] bombEffect = Console.ReadLine()
                .Split(",", StringSplitOptions.RemoveEmptyEntries)
                .Select(int.Parse)
                .ToArray();

            int[] bombCasings = Console.ReadLine()
                .Split(",", StringSplitOptions.RemoveEmptyEntries)
                .Select(int.Parse)
                .ToArray();

            Queue<int> BombQueue = new Queue<int>(bombEffect);
            Stack<int> BombCasing = new Stack<int>(bombCasings);

            int daturaCounter = 0;
            int cherryCounter = 0;
            int smokeCounter = 0;

            bool allBombs = false;

            while (BombCasing.Count > 0 && BombQueue.Count > 0)
            {
                int effect = BombQueue.Peek();
                int casing = BombCasing.Peek();

                if (effect + casing == 40)
                {
                    daturaCounter++;
                    BombCasing.Pop();
                    BombQueue.Dequeue();
                }
                else if (effect + casing == 60)
                {
                    cherryCounter++;
                    BombCasing.Pop();
                    BombQueue.Dequeue();
                }
                else if (effect + casing == 120)
                {
                    smokeCounter++;
                    BombCasing.Pop();
                    BombQueue.Dequeue();
                }
                else
                {
                    BombCasing.Pop();
                    BombCasing.Push(casing - 5);
                }


                if (daturaCounter >= 3 && cherryCounter >= 3 && smokeCounter >= 3)
                {
                    allBombs = true;
                    break;
                }
            }

            //if (daturaCounter >= 3 && cherryCounter >= 3 && smokeCounter >= 3)
            if (allBombs)
            {
                Console.WriteLine("Bene! You have successfully filled the bomb pouch!");
            }
            else
            {
                Console.WriteLine("You don't have enough materials to fill the bomb pouch.");
            }

            if (BombQueue.Count == 0)
            {
                Console.WriteLine("Bomb Effects: empty");
            }
            else if (BombQueue.Count > 0)
            {
                Console.WriteLine($"Bomb Effects: {string.Join(", ", BombQueue)}");

            }
            //Console.WriteLine();
            if (BombCasing.Count == 0)
            {
                Console.WriteLine("Bomb Casings: empty");
            }
            else if (BombCasing.Count > 0)
            {
                Console.WriteLine($"Bomb Casings: {string.Join(", ", BombCasing)}");

            }
            //Console.WriteLine();
            Console.WriteLine($"Cherry Bombs: {cherryCounter}");
            Console.WriteLine($"Datura Bombs: {daturaCounter}");
            Console.WriteLine($"Smoke Decoy Bombs: {smokeCounter}");
        }
    }
}

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