Loading...

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

GalyaHristova avatar GalyaHristova 2 Точки

Retake Mid Exam Technology Fundamentals - Present Delivery C#

Здравейте,

Ще може ли някой да изпрати примерно решение на тази задача - Present Delivery от Retake Mid Exam Technology Fundamentals на C#. Нямам никаква идея как да я направя и ще ми е от полза да видя решението при някой друг :) Благодаря предварително! Това е линка за Judge: https://judge.softuni.bg/Contests/Practice/Index/1395#2

Това е условието:

Problem 3. Present Delivery

Santa has limited time to drop at least some presents for each house. Help him with his mission!

You will receive a string with even integers separated by "@" representing each house with its number of members and a series of Jump commands until you receive "Merry Xmas!"

Santa starts at the position of the first house and has to jump by a given length. The jump command will be in format: "Jump {length}".

Each time he jumps from one house to another he drops 2 presents for that house and decreases the needed presents for that house. If Santa jumps on a house which doesn't need more presents (presents = 0) you should instead print "House {houseIndex} will have a Merry Christmas.".

Keep in mind that Santa can have a bigger jump length than the size of the field and if he does jump outside of it he should start from the beginning again.

For example we have a field of size 3 and each house has 6 members. Santa is at the start and jumps with length of 2. He will end up at index 2 and decrease the needed presents by 2 (6 – 2 = 4). Next he jumps again with length of 2 and ends up at index position 1 and again decreases the needed presents.

 

Input

  • On the first line you will receive a string with even integers separated by "@"houses and their number of members.
  • On the next lines until "Merry Xmas!" you will receive jump commands in format: "Jump {length}".

Output

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

  • "Santa's last position was {lastPositionIndex}."
  • If all members of each house have presents print:
    • "Mission was successful."
  • If not print the count of all houses that won't have a Merry Christmas:
    • "Santa has failed {housesCount} houses."

Constraints

  • The field can be of size [1…20]
  • Each house will have an even number of  members [210]
  • Each jump length will be an integer [120]

 

 

Examples

Input

Output

10@10@10@2

Jump 1

Jump 2

Merry Xmas!

Santa's last position was 3.

Santa has failed 3 houses.

2@4@2

Jump 2

Jump 2

Jump 8

Jump 3

Jump 1

Merry Xmas!

House 0 will have a Merry Christmas.

Santa's last position was 1.

Mission was successful.

 

Тагове:
0
Fundamentals Module
VasilKotsev avatar VasilKotsev 830 Точки

Ето примерно решение на задачата. Тук по-скоро уловката е че ако излезем извън границите на масива трябва за започнем от нулевия индекс.

0
GalyaHristova avatar GalyaHristova 2 Точки

Много благодаря за решението! Видях откъде ми е тръгнала грешката - когато скача повече от дължината, не започвам от началото.

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