C~K要找女朋友了!!!

来源:互联网 发布:淘宝第三方推广网站 编辑:程序博客网 时间:2024/04/29 10:29

C~K要找女朋友了!!!

Time Limit: 1000MS Memory Limit: 131072KB
Submit Statistic

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行,每一行输出一个符合条件的女生的信息。
输出顺序按身高从低到高排序,若身高相同,则按年龄从高到底排序,若年龄也相同,则按照输入顺序输出。

Example Input

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

Example Output

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

Hint

Author

import java.util.*;class Gril{String name;int height;int age;String phone;Gril(String name,int height,int age,String phone){this.name=name;this.height=height;this.age=age;this.phone=phone;}@Overridepublic 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 + ((phone == null) ? 0 : phone.hashCode());return result;}@Overridepublic boolean equals(Object obj) {if (this == obj)return true;if (obj == null)return false;if (getClass() != obj.getClass())return false;Gril other = (Gril) 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 (phone == null) {if (other.phone != null)return false;} else if (!phone.equals(other.phone))return false;return true;}public String print(){return name+" "+height+" "+age+" "+phone;}}public class Main{public static void main(String[] args) {Scanner read=new Scanner(System.in);while(read.hasNext()){int n=read.nextInt();int a=read.nextInt();int b=read.nextInt();int c=read.nextInt();int d=read.nextInt();List<Gril> list=new ArrayList<Gril>();for(int i=0;i<n;i++){String name=read.next();int height=read.nextInt();int age=read.nextInt();String phone=read.next();if(age>=c&&age<=d&&height>=a&&height<=b){Gril gril=new Gril(name,height,age,phone);if(!list.contains(gril)){list.add(gril);}}}Collections.sort(list,new Comparator<Gril>(){public int compare(Gril g1,Gril g2){if(g1.height==g2.height){return g2.age-g1.age;}return g1.height-g2.height;}});System.out.println(list.size());Iterator<Gril> it=list.iterator();while(it.hasNext()){Gril gril=it.next();System.out.println(gril.print());}}read.close();}}

原创粉丝点击