Beijing University of Posts and find the minimum number (java)

题目描述
第一行输入一个数n,1 <= n <= 1000,下面输入n行数据,每一行有两个数,分别是x y。输出一组x y,该组数据是所有数据中x最小,且在x相等的情况下y最小的。 
输入描述:
输入有多组数据。
每组输入n,然后输入n个整数对。
输出描述:
输出最小的整数对。
示例1
输入
复制
5  
3 3  
2 2  
5 5  
2 1  
3 6
输出
复制
2 1
 import java.util.*;
import java.io.*;
import java.math.*;
import java.text.* ;
public class Main
{
	public static void main(String[] args) {
		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			String str;
			while((str=br.readLine()) != null) {
				 int n = Integer.parseInt(str);
				 int x = Integer.MAX_VALUE;
				 int y = Integer.MAX_VALUE;
				 for(int i = 0; i < n; i++) {
					 String[] parts = br.readLine().split(" ");
					 int xn = Integer.parseInt(parts[0]);
					 int yn = Integer.parseInt(parts[1]);
					 if(xn < x || (xn == x && yn < y)) {
						 x = xn;
						 y = yn;
					 }
				 }
				 System.out.println(x+" "+y);
			}				 
		} catch(IOException e) {
			e.printStackTrace();
		}
	}
}



Published 231 original articles · won praise 22 · views 10000 +

Guess you like

Origin blog.csdn.net/weixin_43306331/article/details/104245771