C-K要找女朋友

Problem Description

临近11.11,CK看见周围的朋友一个个的都脱单或者正准备脱单了,CK也想要找一个女朋友了(听说国家会分配?)。MeiK听说了这件事情,表
示CK终于开悟了,所以他整理了一份候选人名单给CK。可是C~K心里有自己心动女生的身高区间和年龄限制,所以他想把符合条件的女生
的信息(即符合[身高最小值,身高最大值]闭区间和[年龄最小值,年龄最大值] 闭区间的女生都算符合条件)给筛选出来,但是这可是难住了CK,事关CK的幸福,你能帮帮他吗?
ps:由于MeiK比较傻,所以名单里可能会有重复的女生的信息,若信息重复,则第一次输入为有效信息。

Input

第一行输入MeiK的候选人名单里有N个人(N<100000)。
第二行输入四个整数a,b,c,d。分别表示C~K心动女生的身高的最小值和最大值,年龄的最小值和最大值。(题目保证a<=b,c<=d)
接下来输入N行,每行表示一个女生的信息(姓名,身高,年龄,联系方式)

ps:联系方式不超过11个字符。

Output

第一行输出一个n,表示符合条件的女生的数量。
接下来的n行,每一行输出一个符合条件的女生的信息。
输出顺序按身高从低到高排序,若身高相同,则按年龄从高到底排序,若年龄也相同,则按照输入顺序输出。

Sample Input

4
160 170 20 22
女神1 161 19 11111
女神2 167 20 22222
女神2 167 20 22222
女神3 163 21 33333

Sample Output

2
女神3 163 21 33333
女神2 167 20 22222

import java.util.*;

class Girl{
	String name;
	int h;
	int age;
	String id;
	public Girl(String name, int h, int age, String id)
	{
		this.name = name;
		this.h = h;
		this.age = age;
		this.id = id;
	}
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + age;
		result = prime * result + h;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Girl other = (Girl) obj;
		if (age != other.age)
			return false;
		if (h != other.h)
			return false;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		return true;
	}
	public String print(){
		return name+" "+h+" "+age+" "+id;
	}
}

public class Main {
	public static void main(String []args)
	{
		Scanner in=new Scanner(System.in);
		List<Girl> list=new ArrayList<Girl> ();
		int n=in.nextInt();
		int a=in.nextInt();
		int b=in.nextInt();
		int c=in.nextInt();
		int d=in.nextInt();
		for(int i=1;i<=n;i++)
		{
			String name=in.next();
			int h=in.nextInt();
			int age=in.nextInt();
			String id=in.next();
			if(h>=a&&h<=b&&age>=c&&age<=d)
			{
				Girl girl=new Girl(name,h,age,id);
				if(!list.contains(girl))
					list.add(girl);
			}
		}
		Comparator<Girl> comparator=new Comparator<Girl>()
		{
			public  int compare(Girl g1,Girl g2)
			{
				if(g1.h==g2.h)
					return g2.age-g1.age;
				else
				return g1.h-g2.h;
			}
		};
			Collections.sort(list,comparator);
			
			System.out.println(list.size());		
			for(Girl girl:list)
			{
				System.out.println(girl.print());
			}
			
		in.close();
	}	
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

奈何碎银没有几两

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值