Loading...
svephoto avatar svephoto 1191 Точки

Здравей, arnold,

 

Би ли дал и условието на задачата (поставено направо тук като текст) + линк към нея в Judge?

0
arnold avatar arnold 50 Точки

https://judge.softuni.bg/Contests/Practice/Index/2031#2

 

Problem 3. Heart Delivery

Valentine’s Day is coming, and Cupid has very limited time to spread some love across the neighborhood. Help him with his mission!

You will receive a string with even integers, separated by a "@". This is our neighborhood. After that a series of Jump commands will follow, until you receive "Love!" Every house in the neighborhood needs a certain number of hearts delivered by Cupid, in order to be able to celebrate Valentine’s Day. Those needed hearts are indicated by the integers in the neighborhood.

Cupid starts at the position of the first house (index 0) and must jump by a given length. The jump commands will be in this format: "Jump {length}".

Every time he jumps from one house to another, the needed hearts for the visited house are decreased by 2. If the needed hearts for a certain house become equal to 0 , print on the console "Place {houseIndex} has Valentine's day." If Cupid jumps to a house where the needed hearts are already 0, print on the console "Place {houseIndex} already had Valentine's day.".

Keep in mind that Cupid can have a bigger jump length than the size of the neighborhood and if he does jump outside of it, he should start from the first house again.

For example, we are given this neighborhood: 6@6@6. Cupid is at the start and jumps with a length of 2. He will end up at index 2 and decrease the needed hearts there by 2: [6, 6, 4]. Next he jumps again with a length of 2 and goes outside the neighborhood, so he goes back to the first house (index 0) and again decreases the needed hearts there: [4, 6, 4].

Input

  • On the first line you will receive a string with even integers separated by "@" – the neighborhood and the number of hearts for each house.
  • On the next lines, until "Love!" is received, you will be getting jump commands in this format: "Jump {length}".

Output

At the end print Cupid's last position and whether his mission was successful or not:

  • "Cupid's last position was {lastPositionIndex}."
  • If each house has had a Valentine's day, print:
    • "Mission was successful."
  • If not, print the count of all houses that didn`t celebrate a Valentine's Day:
    • "Cupid has failed {houseCount} places."

Constraints

  • The neighborhood`s size will be in the range [1…20]
  • Each house will need an even number of hearts in the range [2 … 10]
  • Each jump length will be an integer in the range [1 … 20]

 

 

Examples

Input

Output

Comments

10@10@10@2

Jump 1

Jump 2

Love!

Place 3 has Valentine's day.

Cupid's last position was 3.

Cupid has failed 3 places.

Jump 1 ->> [10, 8, 10, 2]

 

Jump 2 ->> [10, 8, 10, 0] so we print "Place 3 has Valentine's day."

 

Next command is "Love!", so we print Cupid`s last position and the outcome of his mission.

 

2@4@2

Jump 2

Jump 2

Jump 8

Jump 3

Jump 1

Love!

Place 2 has Valentine's day.

Place 0 has Valentine's day.

Place 0 already had Valentine's day.

Place 0 already had Valentine's day.

Cupid's last position was 1.

Cupid has failed 1 places.

 

0
03/07/2021 16:21:02
arnold avatar arnold 50 Точки

Леко я модифицирах, но мръдна от 60/100, на 70/100 и толкова, не иска повече :D

 

https://pastebin.com/rXCCuQm3

0
03/07/2021 16:23:43
svephoto avatar svephoto 1191 Точки

Браво за усилията, продължавай все така упорито борбата с кода yes laugh

Виж аз как я модифицирах за 100/100, дано да ти бъде от полза: https://pastebin.com/iS9bV1KT.

2
krum_43 avatar krum_43 756 Точки

Hello Arnold,

The decision of my colleague Sveпхото is good.
Here we do not have unnecessary empty spaces and the code passes without the command to remove them.

Best!

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