-->
当前位置:首页 > 题库

PROGRAMMING:Genealogical treatment

Luz5年前 (2021-05-10)题库612
Anthropological research is very interested in families, so researchers collected some family genealogies for research. In the experiment, the genealogy was processed by computer. To achieve this goal, the researchers converted the genealogy into a text file. Here is an example of a genealogical text file:
```
John
Robert
Frank
Andrew
Nancy
David
```
In the genealogy text file, each line contains a person's name. The name in the first line is the earliest ancestor of the family. The genealogy contains only the descendants of the earliest ancestors, and their husbands or wives do not appear in the genealogy. Everyone's children indent two more spaces than their parents. Take the above genealogical text file as an example. John, the earliest ancestor of the family, has two children, Robert and Nancy. Robert has two children, frank and Andrew. Nancy has only one child, David.
In the experiment, the researchers also collected family documents and extracted statements about the relationship between two people in the genealogy. The following is an example of a statement of a relationship in a genealogy:
```
John is the parent of Robert
Robert is a sibling of Nancy
David is a descendant of Robert
```
Researchers need to judge whether each statement is true or false. Please write a program to help researchers judge.
###Input format:
Input first gives two positive integers $$n $$($$2 / Le n / Le 100 $$) and $$M $$($$Le 100 $$), where $$n $$is the number of names in the genealogy and $$M $$is the number of statement statements in the genealogy. Each line of input does not exceed 70 characters.
The string of the name consists of no more than 10 English letters. There is no indented space before the name given in the first line of the genealogy. Other names in the genealogy should be indented by at least 2 spaces, that is, they are the descendants of the earliest ancestor (the name given in the first line) in the genealogy. If a name in the genealogy is indented by $$k $$spaces, the name in the next line should be indented by at most $$K + 2 $$spaces.
The same name does not appear twice in a genealogy, and names that do not appear in the genealogy do not appear in statements. The format of each statement is as follows, in which 'x' and 'y' are different names in the Genealogy:
```
X is a child of Y
X is the parent of Y
X is a sibling of Y
X is a descendant of Y
X is an ancestor of Y
```
###Output format:
For each statement in the test case, output 'true' in one line. If the statement is true, or 'false', if the statement is false.
###Input example:
```in
6 5
John
Robert
Frank
Andrew
Nancy
David
Robert is a child of John
Robert is an ancestor of Andrew
Robert is a sibling of Nancy
Nancy is the parent of Frank
John is a descendant of Andrew
```
###Output example:
```out
True
True
True
False
False
```






answer:If there is no answer, please comment