今日頭條大資料崗筆試題一
阿新 • • 發佈:2019-01-09
# 原創作品,轉載請註明出處,謝謝!@楊福星
一、題目介紹
【輸入一系列點,輸出 一系列座標系中最大的點(右方區域無點比其要高)】
二、分析
比其x大的,y都比它小
三、程式設計實現
ToDays .java
package companyTopic.jinritoutiao;
import java.util.Scanner;
/**
* 今日頭條筆試題:輸入一系列點,輸出 一系列座標系中最大的點(右方區域無點比其要高)。比其x大的,y都比它小
*
* @author yangfuxing
*
*/
public class ToDays {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();// 點的數量
System.out.println(num);
XY[] arr_xy = new XY[num];
//輸入點集
for (int i = 0; i < num; i++) {
arr_xy[i] = new XY();
arr_xy[i].x = sc.nextInt();
arr_xy[i].y = sc.nextInt();
}
sc.close();
for (int i = 0; i < arr_xy.length; i++) {
boolean isNull = false;
for (int j = 0; j < arr_xy.length; j++) {
if (arr_xy[j].x > arr_xy[i].x) {
if (arr_xy[j].y > arr_xy[i].y) {
isNull = true;
}
}
}
if (!isNull) {
//輸出“最大的點”集結果
System.out.println(arr_xy[i].x + "\t" + arr_xy[i].y);
}
}
}
}
/**
* 類XY代表包含橫座標x與縱座標y的點
* @author yangfuxing
*
*/
class XY {
/**
* 橫座標x值
*/
int x = 0;
/**
* 縱座標y值
*/
int y = 0;
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
}