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

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

package pp;

import java.util.*;

class Person{
    String name, tel;
    int height, age;
    public Person(String name, int height, int age, String tel) {
        super();
        this.name = name;
        this.height = height;
        this.age = age;
        this.tel = tel;
    }
    @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 + ((tel == null) ? 0 : tel.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;
        Person other = (Person) 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 (tel == null) {
            if (other.tel != null)
                return false;
        } else if (!tel.equals(other.tel))
            return false;
        return true;
    }

    public String toString() {//按照实例输出
        return name + " " + height + " " + age + " " + tel;
    }

}

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()) {
            int n = sc.nextInt();//几个人
            int a = sc.nextInt();
            int b = sc.nextInt();
            int c = sc.nextInt();
            int d = sc.nextInt();
            List<Person>  list = new ArrayList<Person>();

            while(n-- != 0) {
                String name = sc.next();
                int height = sc.nextInt();
                int age = sc.nextInt();
                String tel = sc.next();
                if(age >= c && age <= d && height >= a && height <= b) {
                    Person p = new Person(name, height, age, tel);
                    if(!list.contains(p))//是否已经有相同的
                    {
                        list.add(p);
                    }
                }
            }
             Collections.sort(list, new Comparator<Person>(){//匿名内部类进行排序
                    public int compare(Person o1, Person o2){
                        if(o1.height == o2.height){
                            return o2.age - o1.age;//年龄从高到低输出
                        }

                        return o1.height - o2.height;//身高从低到高输出
                    }
                });
            System.out.println(list.size());//个数
            Iterator<Person> it = list.iterator();
            while(it.hasNext()) {
                System.out.println(it.next());
            }

        }
        sc.close();
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值