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

PROGRAMMING:Icelanders

Luz5年前 (2021-05-10)题库494
In the 2018 World Cup, Iceland became famous for its 1-1 draw with powerful Argentina. The good guy found that there seems to be a "son" behind Icelanders' names, so some netizens popularized science as follows:
![ iceland.JPG](~/73226e55-2588-4d45-b049-a6e72de90872.JPG)
Icelanders follow the ancient patriarchal surname system of the Vikings. A child's surname is equal to his father's name plus a suffix. If he is a son, he will add sson, and his daughter will add sdottir. Because Iceland has a small population, in order to avoid consanguineous reproduction, the local people first use an app to check whether there is any connection between the two ancestors. Please realize the function of this app.
###Input format:
Input first give a positive integer $$n $$($$1 < n / Le 10 ^ 5 $$) in the first line, which is the number of local population. The next $$n $$line, each line gives a person's name, the format is: ` first name and last name (with gender suffix) ', the two strings are composed of no more than 20 lowercase English letters. The descendants of the Vikings can judge their gender by the suffix of their surnames, while others add'm 'after their surnames to indicate male and' f 'to indicate female. The title guarantees that the origin of each given Viking family is male.
The next line gives the positive integer $$M $, which is the number of queries. In the next $$M $$line, each line gives a pair of people's names in the form of 'first name 1 last name 2 last name 2'. Note: the last name here does not have a suffix. All four strings are composed of no more than 20 lowercase English letters.
The title guarantees that there are no two people with the same name.
###Output format:
For each query, the following information is displayed in a row according to the result:
-If two people are heterosexual and have no common ancestor within five generations, output 'yes';
-If two people are of the opposite sex, but have a common ancestor within five generations (excluding the fifth generation), output 'no';
-If two people are of the same sex, output 'whatever';
-If one person is not in the list, output 'na'.
The so-called "no public ancestor within five generations" means that the public ancestors (if any) of two people must be higher than the great grandparents of either side.
###Input example:
```in
fifteen
chris smithm
adam smithm
bob adamsson
jack chrissson
bill chrissson
mike jacksson
steve billsson
tim mikesson
april mikesdottir
eric stevesson
tracy timsdottir
james ericsson
patrick jacksson
robin patricksson
will robinsson
six
tracy tim james eric
will robin tracy tim
april mike steve bill
bob adam eric steve
tracy tim tracy tim
x man april mikes
```
###Output example:
```out
Yes
No
No
Whatever
Whatever
NA
```







answer:If there is no answer, please comment