Loading...
LilianaVelvheva avatar LilianaVelvheva 17 Точки

Къде ми е грешката в задача Ad astra и защо judge ми дава 33 точки?

Ето моя код: https://pastebin.com/KB873m2L

А това е условието на задачата:

Programming Fundamentals Final Exam Retake 15.08.2020

Problem 2. Ad Astra

You are an astronaut who just embarked on a mission across the solar system. Since you will be in space for a long time, you have packed a lot of food with you. Create a program, which helps you  identify how much food you have left and gives you information about its expiration date.

On the first line of the input you will be given a text string. You must extract the information about the food and calculate the total calories.

First you must extract the food info. It will always follow the same pattern rules:

  • It will be surrounded by "|" or "#" (only one of the two) in the following pattern:
    #{item name}#{expiration date}#{calories}#   or
    |{item name}|{expiration date}|{calories}|
  • The item name will contain only lowercase and uppercase letters and whitespace
  • The expiration date will always follow the pattern: {day}/{month}/{year}, where the day, month and year will be exactly two digits long
  • The calories will be an integer between 0-10000

Calculate the total calories of all food items and then determine how many days you can last with the food you have. Keep in mind that you need 2000kcal a day.

Input / Constraints

  • You will receive a single string

Output

  • First print the amount of days you will be able to last with the food you have:

"You have food to last you for: {days} days!"

  • The output for each food item should look like this:
    "Item: {item name}, Best before: {expiration date}, Nutrition: {calories}"

Examples

Input

#Bread#19/03/21#4000#|Invalid|03/03.20||Apples|08/10/20|200||Carrots|06/08/20|500||Not right|6.8.20|5|

Output

Comments

You have food to last you for: 2 days!

Item: Bread, Best before: 19/03/21, Nutrition: 4000

Item: Apples, Best before: 08/10/20, Nutrition: 200

Item: Carrots, Best before: 06/08/20, Nutrition: 500

We have a total of three matches – bread, apples and carrots.

The sum of their calories is 4700. Since you need 2000kcal a day, we divide 4700/2000, which means this food will last you for 2 days.

We print each item

Input

$$#@@%^&#Fish#24/12/20#8500#|#Incorrect#19.03.20#450|$5*(@!#Ice Cream#03/10/21#9000#^#@aswe|Milk|05/09/20|2000|

Output

Comments

You have food to last you for: 9 days!

Item: Fish, Best before: 24/12/20, Nutrition: 8500

Item: Ice Cream, Best before: 03/10/21, Nutrition: 9000

Item: Milk, Best before: 05/09/20, Nutrition: 2000

We have three matches. The total calories are 8500 + 9000 + 2000 = 19500, which means you have food for a total of 9 days.

Input

Hello|#Invalid food#19/03/20#450|$5*(@

Output

Comments

You have food to last you for: 0 days!

We have no matches, which means we have no food.
The colored text is not a match, since it doesn't have a # at the end.

     

JS Input / Output

Input

[

'#Bread#19/03/21#4000#|Invalid|03/03.20||Apples|08/10/20|200||Carrots|06/08/20|500||Not right|6.8.20|5|'

]

Output

Comments

You have food to last you for: 2 days!

Item: Bread, Best before: 19/03/21, Nutrition: 4000

Item: Apples, Best before: 08/10/20, Nutrition: 200

Item: Carrots, Best before: 06/08/20, Nutrition: 500

We have a total of three matches – bread, apples and carrots.

The sum of their calories is 4700. Since you need 2000kcal a day, we divide 4700/2000, which means this food will last you for 2 days.

We print each item

Input

[ '$$#@@%^&#Fish#24/12/20#8500#|#Incorrect#19.03.20#450|$5*(@!#Ice Cream#03/10/21#9000#^#@aswe|Milk|05/09/20|2000|' ]

Output

Comments

You have food to last you for: 9 days!

Item: Fish, Best before: 24/12/20, Nutrition: 8500

Item: Ice Cream, Best before: 03/10/21, Nutrition: 9000

Item: Milk, Best before: 05/09/20, Nutrition: 2000

We have three matches. The total calories are 8500 + 9000 + 2000 = 19500, which means you have food for a total of 9 days.

JavaScript Input

['Hello|#Invalid food#19/03/20#450|$5*(@' ]

Output

Comments

You have food to last you for: 0 days!

We have no matches, which means we have no food.
The colored text is not a match, since it doesn't have a # at the end.

 

 

Тагове:
0
Fundamentals Module
svephoto avatar svephoto 1191 Точки

Здравей, LilianaVelvheva,

 

С някои корекции в регекса и вече си на 100/100, ето коректно работещ вариант:

 

let pattern = /([#|])([A-Za-z\s]+)\1(\d{2}\/\d{2}\/\d{2})\1(\d{1,5})\1/g;

 

В твоето решение частта за обграждащите символи е неправилно написана, имаш излишен интервал след първата група и проверката за калориите трябва да бъде за от 1 до 5-цифрени числа, а не за 1 или повече (независимо колко).

1
09/08/2021 12:50:52
svephoto avatar svephoto 1191 Точки

Моля.

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