17滴滴春招大题

package 套娃问题;


import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.Scanner;


class Node {
public int w;
public int h;


public int getW() {
return w;
}


public void setW(int w) {
this.w = w;
}


public int getH() {
return h;
}


public void setH(int h) {
this.h = h;
}


public Node() {
super();
// TODO 自动生成的构造函数存根
}


public Node(int w, int h) {
super();
this.w = w;
this.h = h;
}
}


public class Test {


public static Comparator<Node> idComparator = new Comparator<Node>() {


public int compare(Node o1, Node o2) {
// TODO 自动生成的方法存根
if ((o1.w - o2.w) > 0 || (o1.h - o2.h) > 0) {
return 1;
}
if ((o1.w - o2.w) < 0 || (o1.h - o2.h) < 0) {
return -1;
}
return 0;
}


};


public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("请输入一个数字:");
int num = in.nextInt();
while (num < 1 || num > 50) {
System.out.println("输入的数字超出约定范围请重新输入:");
num = in.nextInt();
}
int i = 1;
LinkedList<Node> list = new LinkedList<Node>();
while (i <= num) {
System.out.println("输入成对数字: ");
int w = in.nextInt();
int h = in.nextInt();
Node node = new Node(w, h);
list.add(node);
i++;
}
Collections.sort(list,idComparator);
int total=0;
int t1=Integer.MIN_VALUE;
int t2=Integer.MIN_VALUE;
// 遍历
while(!list.isEmpty()){
Node node=list.removeFirst();
if(t1<node.w && t2<node.h){
t1=node.w;
t2=node.h;
total++;
}
}
if(list.size()==0){
System.out.println(0);
}else{
System.out.println(total);
}

}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值