2 shunfurh shunfurh 于 2017.09.10 18:37 提问

Genealogical Research

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 ::= <>

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.

Output

The BIRTH, DEATH, and QUIT commands have no output. For each ANCESTORS (DESCENDANTS) command, print the following information:

  1. Print a line containing "ANCESTORS of" ("DESCENDANTS of") followed by the person's name
  2. 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.
  3. Print the ancestry (descendant) information for the parent (child), indented another 2 spaces, using these same steps (i.e. steps 2-4).
  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. 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.

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个回答

devmiao
devmiao   Ds   Rxr 2017.09.27 21:52
已采纳
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!
其他相关推荐
Genealogical tree(拓扑排序问题——基础)
Network Time Limit: 1000ms Memory Limit: 10000KB 64-bit integer IO format: %lld      Java class name: Main Submit Status A Telephone Line Company (TLC) is establishing a new telephone
Genealogical Tree
Genealogical Tree
Genealogical tree(拓扑排序)
Genealogical tree Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Submit Status Description The system of Martians' blood relations is confusing enough. Ac
Genealogical tree(POJ 2367)
Genealogical tree Time Limit: 1000MS Memory Limit: 65536K Description The system of Martians’ blood relations is confusing enough. Actually, Martians bud when they want and where they want. Th...
POJ 2367 Genealogical tree 拓扑排序
本题属于最基础的拓扑排序。大意就是,给出一个数n, 然后底下n行,编号1到n, 每行输入几个数,保证结果中该行的编号要在这几个数前面。 /* ID: sdj22251 PROG: calfflac LANG: C++ */ #include #include #include #include #include #include #include #include #incl
拓扑排序—入门简单题—Genealogical tree
题目链接 题目大意: 给出n个点,给出n种关系,第i行对应i->x(先后顺序),求出一个序列,使得满足以上所有的关系.如果有多个这样的序列,求出一个就行。测试数据有大于等于1个的序列。 思路:这是最基本的拓扑排序的题,用G[maxn]用来存图,入度为0存一个,ans用来存输出顺序。 代码: #include #include #include #include using
ural 1022. Genealogical Tree
裸的拓扑排序。昨晚btw一写,我才觉得,我以前写的拓排,真慢啊真慢。。他直接用DFS盖时间戳了 。。。T T。。。这个是btw的代码。。。#include #include #include #define N 100 static int g[N + 1][N + 1]; static int n; static int toporder[N + 1]; static int count; static char used[N + 1]; static void topsort(v
如何做research的思考?
### Date: 2017/5/20 之前在某个论坛上看到的,感觉比较好,分享给大家。 如何找题目: 1,首先很广泛的的看领域内的top conference的paper,或者看看这个领域的大牛写的survey paper。 这一步可以称为“survey”阶段。这里你需要了解各个领域大概是在做什么样的问题。这个阶段只需要看paper的abstract,introduction,relat
如何关闭word2007中的Research窗口
对于第一次使用Word2007它所带有的丰富的功能相当令人感叹,但是很遗憾的是出现了以下这个问题让我苦恼了好久。 问题描述:word中出现Research这个窗口,对word进行的所有快捷键、鼠标右键、滚动鼠标、输入法等操作全都失效。为此我真是郁闷了半天啊!最后终于找到这个问题的解决方法了。 解决方法:选择Reasearch窗口,同时按下Ctrl+Alt+”+“(小键盘上的+) 你可以尝试一
W. Winston, Operations Research Applications and Algorithms
W. Winston, Operations Research Applications and Algorithms