描述
Professor John is investigating a math problem. He has obtained some relations among several variables. Now he would like to know if there are any other relations that can be deduced from these obtained ones. For example, the known relations are given as follows: A < B, C > B and C < D, other relations including A < C, A < D and B < D can be deduced. Since he has been working for too long, Professor John decides to grant himself a vacation while assigning you to do the job. Are you ready?
输入
The first line of input contains an integer N, which is the number of test cases. Then N test cases follow. For each test case: the 1st line contains a positive integer m (<= 100) which is the number of given relations; the following m lines each contains a given relation, in the format Variable1 < Variable2 or Variable1 > Variable2
A "Variable" is represented by a capital character. There will not be conflicting relations given.
输出
For each test case, first print in one line "Case d:" where d is the number of the test case, start counting from 1. Then output all the relations which can be deduced from the given relations in alphabetical order, in the format Variable1 < Variable2. Each relation occupies one line. No extra space shall be printed. The given relations must NOT be included. If no new relation is found, output "NONE" in one line.
OpenJudge - 3529:Professor John
翻译
描述
约翰教授正在研究一道数学题。他得到了几个变量之间的一些关系。现在他想知道从这些关系式中是否还能推导出其他关系式。例如,已知关系给出如下:A < B, C > B和C < D,其他关系包括A < C, A < D, B < D。由于他已经工作了太长时间,约翰教授决定给自己一个假期,同时指派你做这项工作。你准备好了吗?
输入
输入的第一行包含一个整数N,它是测试用例的数量。然后是N个测试用例。对于每个测试用例:第一行包含一个正整数m(<= 100),这是给定关系的数量;下面的m行每一行都包含一个给定的关系,格式为Variable1 < Variable2或Variable1 > Variable2
“变量”由大写字符表示。不会有冲突的关系。
输出
对于每个测试用例,首先在一行中输出“Case d:”,其中d是测试用例的序号,从1开始计算。然后按字母顺序输出从给定关系导出的所有关系,格式为Variable1 < Variable2。每个关系占据一条直线。没有额外的空间应印刷。不应包括给定的关系。如果没有找到新的关系,则在一行中输出“NONE”。