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
Output
2
女神3 163 21 33333
女神2 167 20 22222
import java.util.*;
//需要重写compareTo
class Girl implements Comparable<Girl>{
String name,cell;
int high,age;
public Girl(String name, int high, int age, String cell) {
super();
this.name = name;
this.cell = cell;
this.high = high;
this.age = age;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + age;
result = prime * result + ((cell == null) ? 0 : cell.hashCode());
result = prime * result + high;
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 (cell == null) {
if (other.cell != null)
return false;
} else if (!cell.equals(other.cell))
return false;
if (high != other.high)
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
return true;
}
@Override
public int compareTo(Girl o) {
if(this.high == o.high)
return o.age-this.age;
else
return this.high-o.high;
}
@Override
public String toString() {
// TODO Auto-generated method stub
return name+" "+high+" "+age+" "+cell;
}
}
public class Main {
public static int minAge, maxAge, minHigh, maxHigh;
public static boolean f(int h,int age) {
if(age>=minAge && age<=maxAge && h<=maxHigh && h>=minHigh)
return true;
else
return false;
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
List<Girl> list = new ArrayList<Girl>();
String name,cell;
int age,h;
Girl girl;
int n = input.nextInt();
minHigh = input.nextInt();
maxHigh = input.nextInt();
minAge = input.nextInt();
maxAge = input.nextInt();
for(int i=0; i<n; i++) {
name = input.next();
h = input.nextInt();
age = input.nextInt();
cell = input.next();
if(f(h,age)) {
girl = new Girl(name,h,age,cell);
if(!list.contains(girl)) {
list.add(girl);
}
}
}
Collections.sort(list);
System.out.println(list.size());
for(Girl g : list)
System.out.println(g);
input.close();
}
}