Family Tree_Java advanced Exercise
Здравейте,
Имам една логика за тази задача, която не мога да докарам до край. Може ли някой да погледне и да каже въобще може ли да се довърши по този начин.
Пазя данните в два мапа родители и деца String String - - ключ име и стойност години, при зададено само име - слагам празен стринг за дата, и обратно.
При получаване на липсващите данни после, не мога да сменя ключа от празен стринг на името да отиде на същата позиция, където е бил. Мога да го добавя накрая, а така не изпълнявам условието за поредност на данните.
Ако някой има и линк за решена задача от лекторите, моля да сподели.
https://pastebin.com/3CPwhsZN
https://judge.softuni.bg/Contests/Practice/Index/1518#7
Условие:
You want to build your family tree, so you went to ask your grandmother, sadly your grandmother keeps remembering information about your predecessors in pieces, so it falls to you to group the information and build the family tree.
On the first line of the input you will receive either a name or a birthdate in the format "<FirstName> <LastName>" or "day/month/year" - your task is to find information about the person in the family tree. On the next lines until the command "End" is received you will receive information about your predecessors that you will use it to build the family tree.
The information will be in one of the following formats:
- "FirstName LastName - FirstName LastName"
- "FirstName LastName - day/month/year"
- "day/month/year - FirstName LastName"
- "day/month/year - day/month/year"
- "FirstName LastName day/month/year"
The first 4 formats reveal a family tie – the person on the left is parent to the person on the right (as you can see the format does not need to contain names, for example the 4th format means the person born on the left date is parent to the person born on the right date). The last format ties different information together – i.e. the person with that name was born on that date. Names and birthdates are unique – there won’t be 2 people with the same name or birthdate, there will always be enough entries to construct the family tree (all people names and birthdates are known and they have atleast one connection to another person in the tree).
After the command "End" is received you should print all information about the person whose name or birthdate you received on the first line – his name, birthday, parents and children (check the examples for the format). The people in the parents and children lists should be ordered by their first appearance in the input (regardless if they appeared as a birthdate or a name, for example in the first input Stamat is before Penka because he first appeared in the second line, while she appears in the third.).
Examples
Input |
Output |
Pesho Peshev 11/11/1951 - 23/05/1980 Penka Pesheva - 23/05/1980 Penka Pesheva 09/02/1953 Pesho Peshev - Gancho Peshev Gancho Peshev 01/01/2005 Stamat Peshev 11/11/1951 Pesho Peshev 23/05/1980 End |
Pesho Peshev 23/05/1980 Parents: Stamat Peshev 11/11/1951 Penka Pesheva 09/02/1953 Children: Gancho Peshev 01/01/2005 |
13/12/1993 25/03/1934 - 04/04/1961 Poncho Tonchev 25/03/1934 04/04/1961 - Moncho Tonchev Toncho Tonchev - Lomcho Tonchev Moncho Tonchev 13/12/1993 Lomcho Tonchev 07/07/1995 Toncho Tonchev 04/04/1961 End |
Moncho Tonchev 13/12/1993 Parents: Toncho Tonchev 04/04/1961 Children: |