Софтуерно Инженерство
Loading...
+ Нов въпрос
MartinPL avatar MartinPL 0 Точки

Easter Gifts Mid Exam 2019

Здравейте, реших да пробвам да реша изпитните задачи от преди няколко дни, но ударих на камък и лошото е че не мога да разбера къде. Гледам го и не мога да си намеря грешките, а те са доста, защото получавам само 33 точки с 2 грешни отговора и 5 рън тайм еръра.  Интересно ми е защо на двата пробни теста от условието получавам верен отговор, но само на тях. Ако някой може да ми обясни къде греша бих бил много благодарен, защото явно правя една и съща грешка на всички задачи с Листи. Благодаря предварително! 

https://pastebin.com/40uKu8uL

Условието : 

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 25/06/2019 00:36:48
mark79 avatar mark79 561 Точки

Здравей,

малко преработих кода ти, но не виждам защо трябва да използваш List-ове. Можеш спокойно да работиш с масива, след split-a.

Ето, какво се получи.

Поздрави.

0