编程介的小学生 2017-12-07 17:48 采纳率: 20.5%
浏览 725
已采纳

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

  • 写回答

1条回答 默认 最新

  • threenewbee 2018-02-26 15:10
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog