Problem Description
临近11.11,C~K看见周围的朋友一个个的都脱单或者正准备脱单了,C~K也想要找一个女朋友了(听说国家会分配?)。MeiK听说了这件事情,表
示C~K终于开悟了,所以他整理了一份候选人名单给C~K。可是C~K心里有自己心动女生的身高区间和年龄限制,所以他想把符合条件的女生
的信息(即符合[身高最小值,身高最大值]闭区间和[年龄最小值,年龄最大值] 闭区间的女生都算符合条件)给筛选出来,但是这可是难住了C~K,事关C~K的幸福,你能帮帮他吗?
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 height;
int age;
String telephone;
public Girl(String name, int height, int age, String telephone) {
super();
this.name = name;
this.height = height;
this.age = age;
this.telephone = telephone;
}
@Override
public String toString() {
return name + " " + height + " " + age + " " + telephone;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + age;
result = prime * result + height;
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((telephone == null) ? 0 : telephone.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 (height != other.height)
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
if (telephone == null) {
if (other.telephone != null)
return false;
} else if (!telephone.equals(other.telephone))
return false;
return true;
}
}
public class Main {
public static void main(String[] args){
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int a = in.nextInt();
int b = in.nextInt();
int c = in.nextInt();
int d = in.nextInt();
Set<Girl> set = new HashSet<Girl>();
for(int i = 0; i < n; i++)
{
String name = in.next();
int height = in.nextInt();
int age = in.nextInt();
String telephone = in.next();
if(height >= a && height <= b && age >= c && age <= d)
{
Girl girl = new Girl(name, height, age, telephone);
set.add(girl);
}
}
ArrayList<Girl> list = new ArrayList<Girl>(set);
Collections.sort(list, new Comparator<Girl>() {
@Override
public int compare(Girl o1, Girl o2) {
int r1 = o1.height - o2.height;
if(r1 != 0)
{
return r1;
}
else
{
return o2.age - o1.age;
}
}
});
System.out.println(list.size());
for(Girl girl:list)
{
System.out.println(girl);
}
in.close();
}
}