编程介的小学生 2017-04-10 01:29 采纳率: 20.5%
浏览 837
已采纳

Inheritance

One of your old friends is now developing a new programming language. He wants to make it the best programming language ever, or at least the best at most phases. So it is an Object-Oriented Programming language of course. He thinks most OOP languages at present are too inefficient with the handling of inheritance and polymorphism, and he wants to make this quicker in his own language. However, he isn't good at algorithm himself, so he comes to you, a well-known ACMer, and is now asking you to help him.
With the inheritance relations input, your program is asked to check whether an object can acted as a parameter of a given class in function calls. (As a pure OOP language, multiple inheritance is not considered)

Input

For each test case (project), the first line is the name of the common base class in the language (the base class of all classes in this language, because the language is still in developing, its name has not been fixed) and an integer N (1 <= N <= 30,000), the number of classes in this project, then N lines follow. Each line contains two class names A and B, specifying that class A is derived from class B. All A's will be different in the N lines, and you may assume that all classes will be derived from the common base class directly or indirectly. After that there is an integer M (1 <= M <= 30,000), the number of pairs of classes to be checked and then M lines follow. Each line contains two class names C and D, you are asked to check whether an instance of class C is class D (an instance of class D or a class derived from D, for example, if you're a student, you're a human, because student is a derived class of human). All class name will be non-space charaters with length no more than 255.

These's a blank line between every two cases, processing to the end of file.

Output

For each test case, in the first line output "Project K" where K is the case index starts from 1.

For each pairs of C and D, you program should print "Yes" or "No" in one line according to whether an instance of class C is class D.

Print a blank line between consecutive cases.

Sample Input

Object 3
Integer Object
List Object
LinkedList List
3
Integer Object
LinkedList List
Integer List
Sample Output

Project 1
Yes
Yes
No

  • 写回答

1条回答 默认 最新

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站