Професионална програма
Loading...
+ Нов въпрос
arnold avatar arnold 29 Точки

Problem 5. Fashion Boutique (C#)

80/100 Никак не ми показват тестовете къде мога да греша, нещо в условието ли изпускам, може и аз да не съм се сетил за по-добър начин на решаването й? Ако някой има желание, може да хвърли едно око и да помогне:

https://pastebin.com/MqMQqWJG

https://judge.softuni.org/Contests/Practice/Index/1447#4

 

Fashion Boutique

You own a fashion boutique and you receive a delivery once a month in a huge box, which is full of clothes. You have to arrange them in your store, so you take the box and start from the last piece of clothing on the top of the pile to the first one at the bottom. Use a stack for the purpose. Each piece of clothing has its value (an integer). You have to sum their values, while you take them out of the box. You will be given an integer representing the capacity of a rack. While the sum of the clothes is less than the capacity, keep summing them. If the sum becomes equal to the capacity you have to take a new rack for the next clothes, if there are any left in the box. If it becomes greater than the capacity, don't add the piece of clothing to the current rack and take a new one. In the end, print how many racks you have used to hang all of the clothes.

Input

  • On the first line you will be given a sequence of integers, representing the clothes in the box, separated by a single space
  • On the second line, you will be given an integer, representing the capacity of a rack

Output

  • Print the number of racks, needed to hang all of the clothes from the box

Constraints

  • The values of the clothes will be integers in the range [0,20]
  • There will never be more than 50 clothes in a box
  • The capacity will be an integer in the range [0,20]
  • None of the integers from the box will be greater than then the value of the capacity

Examples

Input

Output

5 4 8 6 3 8 7 7 9

16

5

1 7 8 2 5 4 7 8 9 6 3 2 5 4 6

20

5

 

Тагове:
0
Module: C# Advanced 03/09/2021 13:59:55
icowwww avatar icowwww 1577 Точки
Best Answer

Здравей,

Трябва да проверяваш дали рафта ще се препълни, ако добавиш новата стойност към сумата.

If it becomes greater than the capacity, don't add the piece of clothing to the current rack and take a new one

Промених логиката в цикъла, защото 

if (sumClothes < capacityOfRack) това доста се разминава с условието.

Цялото с коментари: https://pastebin.com/Ms2Szg8R

1
03/09/2021 23:43:17
arnold avatar arnold 29 Точки

Благодаря много!

0
arnold avatar arnold 29 Точки

Иначе съм търсил грешката не там, където трябва. Правих си проверки ако се дадат на входа данни като 0 0 0, с 0 капацитет и изкарва 1, което пак минава на 100/100, а не би трябвало :D

0
04/09/2021 14:33:23