1. 程式人生 > >今日頭條大資料崗筆試題一

今日頭條大資料崗筆試題一

# 原創作品,轉載請註明出處,謝謝!@楊福星

一、題目介紹

【輸入一系列點,輸出 一系列座標系中最大的點(右方區域無點比其要高)】

題目背景介紹
輸入輸出

二、分析

 比其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; } }

四、結束語

*此筆記謹供情況相似者參考!

*歡迎交流學習!博主知識淺薄,希望有不對的地方能得到您的指正!謝謝!^_^

**轉載請註明出處,謝謝!!!