您的位置:首页 > 大数据

[置顶] 今日头条大数据岗笔试题一

2017-08-22 21:59 260 查看

# 原创作品,转载请注明出处,谢谢!@杨福星

(http://blog.csdn.net/luckystar92/article/details)

一、题目介绍

【输入一系列点,输出 一系列坐标系中最大的点(右方区域无点比其要高)】





二、分析

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

}


四、结束语

*阿星的博客(http://blog.csdn.net/luckystar92)

*此笔记谨供情况相似者参考!

*欢迎交流学习!博主知识浅薄,希望有不对的地方能得到您的指正!谢谢!^_^

**转载请注明出处,谢谢!!!

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: