Loading...

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

silvana1303 avatar silvana1303 5 Точки

Lootbox - C# Advanced Exam - 22 Feb 2020

Имам проблем с тази задача, не сумира числата в случаите, в които сбора е четно число, може някой да каже къде греша?

кода: https://pastebin.com/4vQBeHC1

Условие:

Loot box

 

You are tired of being the only one on your team without cool items, so you decided buy some loot boxes which have a chance to drop some cool items.

Every purchase gives you two loot boxes and they are represented as a sequence of integers. First, you will be given a sequence of integers, representing the first loot box. Afterwards, you will be given another sequence of integers representing the second loot box.

You need to start from the first item in the first box and sum it with the last item in the second box. If the sum of their values is an even number, add the summed item to your collection of claimed items and remove them both from the boxes. Otherwise, move the last item from the second box and add it at the last position in the first box. You need to stop summing items when one of the boxes becomes empty.

If the first loot box becomes empty print:

               "First lootbox is empty"

If the second loot box becomes empty print:

               "Second lootbox is empty"

In the end you need to determine the quality of your claimed items. If the sum of the claimed items equal to or greater than 100, print:

               "Your loot was epic! Value: {sum of claimed items}"

Else print:

      "Your loot was poor... Value: {sum of claimed items}"

Input

  • On the first line, you will receive the integers representing the first loot box, separated by a single space.
  • On the second line, you will receive the integers representing the second loot box, separated by a single space.

Output

  • On the first line of output – print which box got empty in the format described above.
  • On the second line – the quality of your loot in the format described above.

Constraints

  • All of the given numbers will be valid integers in the range [0, 100].
  • There won’t be a case where both loot boxes become empty at the same time.

Examples

Input

Output

Comment

10 11 8 13 5 6

0 4 7 3 6 23 3

Second lootbox is empty

Your loot was poor... Value: 42

First we sum 10 and 3. We get 13, which is not an even number, so we take the last item from the second box and move it to last position in the first box. The current state of the boxes:

10 11 8 13 5 6 3

0 4 7 3 6 23

The next sum is 33 so we do the same again. On the third iteration the sum is 16 which is an even number, so we remove both of the boxes and we add the value to our claimed items. We keep summing items until one of the boxes becomes empty.

20 40 60 80 100

10 20 30 40 50 60

First lootbox is empty

Your loot was epic! Value: 500

 

 

 

 

 

 

Тагове:
0
C# Advanced 21/10/2020 18:07:46
Axiomatik avatar Axiomatik 2422 Точки
Best Answer

Everything is OK, just change line 21 from

if (first.Peek() + second.Peek() % 2 == 0)

to

if ((first.Peek() + second.Peek()) % 2 == 0)

Otherwise, modular division will only be applied on second.Peek(), which is why the validation was not working.

Best,

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