Loading...

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

Dimitar_Milenkov avatar Dimitar_Milenkov 1 Точки

10.LadyBugs - C# Exercise Arrays

Здравйте,

Написах този код след много дълго мислене над задачата. Накрая измислих решение, което е дълго и може би ненужно. Но в Judge ми дава 20/100 и всичко останало е Runtime Error. Мисля, че е заради дългия код, но ако някой мисли, че има друго решение на проблема, да сподели. Погледнах и пишеше, че ако променя int променливи с long е възможно да се премахне грешката, но не стана.

Заданието:

1.*LadyBugs

You are given a field size and the indexes where ladybugs can be found on the field. On every new line, until the "end" command is given, a ladybug changes its position either to its left or to its right by a given fly length. A movement description command looks like this: "0 right 1". This means that the little insect placed on index 0 should fly one index to its right. If the ladybug lands on another ladybug, it continues to fly in the same direction repeating the specified flight length. If the ladybug flies out of the field, it is gone.

For example, you are given a field of size 3, where there are ladybugs on indexes 0 and 1. If the ladybug on index 0 needs to fly to its right by the length of 1 (0 right 1), it will attempt to land on index 1 but as there is another ladybug there, it will continue further to the right passing 1 index in length, landing on index 2. After that, if the same ladybug needs to fly to its right passing 1 index (2 right 1), it will land somewhere outside of the field, so it flies away:

If we receive an initial index that does not contain a ladybug, nothing happens. If you are given a ladybug index that is outside the field, nothing happens. In the end, print all cells of the field separated by blank spaces. For each cell that has a ladybug in it print '1' and for each empty cell print '0'. The output of the example above should be "0 1 0".

Input

  • On the first line, you will receive an integer - the size of the field.
  • On the second line, you will receive the initial indexes of all ladybugs separated by a blank space.
  • On the next lines, until you get the "end" command, you will receive commands in the format: "{ladybug index} {direction} {fly length}".

 

Output

  • Print all field cells in format: "{cell} {cell} … {cell}"
    • If a cell has a ladybug in it, print '1'.
    • If a cell is empty, print '0'.

Constrains

  • The size of the field will be in the range [0…1000].
  • The ladybug indexes will be in the range [-2147483647…2147483647].
  • The number of commands will be in the range [0…100].
  • The fly length will be in the range [-2147483647…2147483647].

Examples

Input

Output

Comments

3

0 1

0 right 1

2 right 1

end

0 1 0

1 1 0 - initial field

0 1 1 - field after "0 right 1"

0 1 0 - field after "2 right 1"

 

Input

Output

 

Input

Output

3

0 1 2

0 right 1

1 right 1

2 right 1

end

0 0 0

 

5

3

3 left 2

1 left -2

end

0 0 0 1 0

 Ето и кода: 

https://pastebin.com/FmCq9mhh

 

Тагове:
0
C# Fundamentals
Milena_B avatar Milena_B 8 Точки

Това е моето решение, което дава 100/100. Надявам се да ти помогне. :)

https://pastebin.com/cnVQUaET

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