Santa's new list C# Retake exam 10 January Part II
Здравейте.Моля за помощ на следната задача:
Santa’s New List
Santa needs to start creating his new list for the next Christmas. Your job is to help him receive and keep the incoming information. He will receive information about the names of the children, the type of present they want (toy, candy, clothing) and the wanted amount in the following format:
{childName}->{typeOfToy}->{amount}
You can receive a command “Remove->{childName}”. In this case, you need to exclude the child from the new list with good children, but don’t change the information about the type of present he or she wanted and the wanted amount. Santa has already gotten the presents, so he might give them to another very good child.
When you receive the “END” command, you need to process it and print it, ordered descending by the total amount of presents for a child and then by their names. The format is given bellow.
Input
Until you receive "END" command you will be receiving information about the wanted presents in the following format:
"{childName}->{typeOfPresent}->{amount}".
You can receive a command to remove a child from the list -> "Remove->{childName}"
Output
- Print the presents for each child, ordered descending by the total amount and then by their name, in the following format:
Children:
{childName} -> {points}
- After that print type of present and the total count for it in the following format:
Presents:
{type} –> {count}
Constraints
- The count of presents will always be a valid integer in the range [0-100];
Examples
Input |
Output |
Comment |
Marty->Toys->5 Sam->Candy->20 Leo->Candy->10 Leo->Toys->1 Katy->Clothes->4 Bobbie->Clothes->6 Tanya->Phone->1 Nasko->Tablet->3 END |
Children: Sam -> 20 Leo -> 11 Bobbie -> 6 Marty -> 5 Katy -> 4 Nasko -> 3 Tanya -> 1 Presents: Toys -> 6 Candy -> 30 Clothes -> 10 Phone -> 1 Tablet -> 3 |
First, we receive “Marty”, then “Sam”, then “Leo”. When we receive “Leo” for the second time, we have to add the amount the new type of present he wants to his total count of present for receiveing. We receive “Candy” as a type for the second time, we need to add the amount to the total count of that type. In the end, we print first the children, ordered descending by the total count of the presents they want and then by their names. |
Teddy->Clothes->8 Johny->Toys->10 Freddie->Candy->30 Johny->Candy->20 Carrie->Phone->1 Carrie->Tablet->1 Carrie->Candy->10 Teddy->Toys->5 Remove->Teddy END |
Children: Freddie -> 30 Johny -> 30 Carrie -> 12 Presents: Clothes -> 8 Toys -> 15 Candy -> 60 Phone -> 1 Tablet -> 1 |
|
Ето кода ми:
https://pastebin.com/30hfTVKK
Ами да,омотал съм се в условието и по-точно гледайки долу обясненията...Благодаря!