编程介的小学生 2017-09-24 07:52 采纳率: 20.5%
浏览 756
已采纳

Genealogical Research

Description

These days, everyone seems to be exploring their ancestry. This effort is supported by family history software, now marketed by a number of vendors. Unfortunately this software is expensive and runs only on the McDoze X operating system. You are to write an open-source equivalent.
Input

Your program accepts a series of commands, one per line. The commands are described by the following syntax:
command ::= birth

       ::= death

       ::= ancestors

       ::= descendants 

       ::= QUIT

birth ::= BIRTH child: date: mother: father

death ::= DEATH person: date

ancestors ::= ANCESTORS person

descendants ::= DESCENDANTS person

child ::= name

mother ::= name

father ::= name

person ::= name

date ::= name

name ::= [any sequence of characters not beginning or ending with a space or containing a colon]

Spaces in the input are ignored except where they appear within name. The BIRTH and DEATH commands record the birth and death of an individual. You may assume that each individual has a unique name. The ANCESTORS and DESCENDANTS commands are queries: they print a family tree or a reverse family tree for the named person, using the BIRTH and DEATH information entered by previous commands. The QUIT command indicates the end of input.
You may assume that no input line exceeds 100 characters, and that there are not more than 250 lines of input. You may assume that DEATH, ANCESTORS, and DESCENDANTS commands refer to a name for which a BIRTH command has previously been given. QUIT appears only as the last line of input.
Output

The BIRTH, DEATH, and QUIT commands have no output. For each ANCESTORS (DESCENDANTS) command, print the following information:
Print a line containing "ANCESTORS of" ("DESCENDANTS of") followed by the person's name
Indented 2 spaces from the previous line, print the person's first parent (child) in alphabetical order, followed by the parent's (child's) birth date, followed by a space, followed by a hyphen, and, if the parent (child) has died, another space and the date of death. If there is no birth record for the parent (child), print the name alone.
Print the ancestry (descendant) information for the parent (child), indented another 2 spaces, using these same steps (i.e. steps 2-4).
Repeat steps 2-4 for the remaining parent (children). Indentation should be the same as for the previous parent (child).

Leave an empty line between the output sequences for successive commands.
Sample Input

BIRTH John Doe : January 7, 1599 : Jane Doe : Adam Doe
BIRTH Mary Worth : May 18, 1666 : Jane Doe : Adam Doe
BIRTH Casper Ghost : Jan 2, 1959 : Mary Worth : John Doe
DEATH Mary Worth : Jan 3, 1959
ANCESTORS Casper Ghost
DESCENDANTS John Doe
QUIT
Sample Output

ANCESTORS of Casper Ghost
John Doe January 7, 1599 -
Adam Doe
Jane Doe
Mary Worth May 18, 1666 - Jan 3, 1959
Adam Doe
Jane Doe

DESCENDANTS of John Doe
Casper Ghost Jan 2, 1959 -

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-10-11 10:39
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 想问一下stata17中这段代码哪里有问题呀
  • ¥15 flink cdc无法实时同步mysql数据
  • ¥100 有人会搭建GPT-J-6B框架吗?有偿
  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决