2 shunfurh shunfurh 于 2017.12.08 01:48 提问

For

Problem Description
LMY is a mathematics lover. Now LMY likes to play matrix. LMY designs such a matrix problem. In a large matrix, there are some elements has been marked. For every marked element, return a marked element whose row and column are larger than the original marked element’s row and column respectively. If there are multiple solutions, return the element whose row is the smallest; and if there are still multiple solutions, return the element whose column is the smallest. If there is no solution, return -1 -1.
Of course LMY wants YY also like matrix. So she lets YY develop a program to solve the problem. But YY is very busy now. He should learn English for his enrollment examination for Ph.D. students. Could you help YY develop the program?

Input
The input consists of multiple test cases. For each test case, the first line contains only one integer n. n ≤ 1000. Each of the next n lines describes a marked element’s row and column. A marked element’s row and column can be repeatedly showed. There is a blank line between two consecutive test cases.
End of input is indicated by a line containing a zero.

Output
Start each test case with "Case #:" on a single line, where # is the case number starting from 1. For each element’s row and column, output the result. The format is showed as sample output. There is a blank line between two consecutive test cases.

Sample Input
5
1 8
5 7
6 9
2 8
3 1

10
7 5
7 5
3 1
9 9
1 4
7 4
2 3
9 5
4 5
3 4

0

Sample Output
Case 1:
6 9
6 9
-1 -1
6 9
5 7

Case 2:
9 9
9 9
4 5
-1 -1
4 5
9 5
3 4
-1 -1
9 9
4 5

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!