Професионална програма
Loading...
Vesolini avatar Vesolini 7 Точки

2.Easter Gifts Mid Exam

Здравейте,

Опитвам се да реша задачите от предходни изпити и попаднах на Easter Gifts https://judge.softuni.bg/Contests/Practice/DownloadResource/5618.

Може ли някой да ми каже къде греша и защо judge ми дава 70/100 със този код : https://pastebin.com/9dcw7LLS

Все още се уча на масиви и ще се радвам ако някой ми каже по добър вариант на задачата. 

 

П.С Ако не ви се отвори линка с условието на задачаата ------>

 

Create a program that helps you plan the gifts for your friends and family. First, you are going to receive the gifts you plan on buying оn a single line, separated by space, in the following format:

"{gift1} {gift2} {gift3}… {giftn}"

Then you will start receiving commands until you read the "No Money" message. There are three possible commands:

  • "OutOfStock {gift}"
    • Find the gifts with this name in your collection, if there are any, and change their values to "None".  
  • "Required {gift} {index}"
    • Replace the value of the current gift on the given index with this gift, if the index is valid.
  • "JustInCase {gift}"
    • Replace the value of your last gift with this one.

In the end, print the gifts on a single line, except the ones with value "None", separated by a single space in the following format:

"{gift1} {gift2} {gift3}… {giftn}"

Input / Constraints

  • On the 1st line you are going to receive the names of the gifts, separated by a single space.
  • On the next lines, until the "No Money" command is received, you will be receiving commands.
  • The input will always be valid.

Output

  • Print the gifts in the format described above.

Examples

Input

Output

Eggs StuffedAnimal Cozonac Sweets EasterBunny Eggs Clothes

OutOfStock Eggs

Required Spoon 2

JustInCase ChocolateEgg

No Money

StuffedAnimal Spoon Sweets EasterBunny ChocolateEgg

Comments

First, we receive the command "OutOfStock" and we need to replace the values of "Eggs" with "None".  After this command the list should look like this:

None StuffedAnimal Cozonac Sweets EasterBunny None Clothes.

Afterwards, we receive the "Required" command and we need to replace the value on the 2nd index of our list with the value "Spoon". The list should look like this:  

None StuffedAnimal Spoon Sweets EasterBunny None Clothes

After, we receive the "JustInCase" command, which means we need to replace the last value in our list with "ChocolateEggs". The list should look like this:

None StuffedAnimal Spoon Sweets EasterBunny None ChocolateEggs

In the end, we print all of the gifts, except the ones with values "None". This is the result list:

StuffedAnimal Spoon Sweets EasterBunny ChocolateEggs

 

Тагове:
0
Fundamentals Module
knoteva avatar knoteva 1079 Точки

Здравей,

При "Required" трябва да имаш и проверка дали num >= 0.

0
Vesolini avatar Vesolini 7 Точки

Много благодаря !

То си пише в задачата "if the index is valid", но изглежда не съм му обърнал внимание. Добре, че ми каза, че иначе не знам колко време щях да го мисля :)

0