C~K要找女朋友了!!!
Time Limit: 1000 ms Memory Limit: 131072 KiB
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
Hint
Source
C~K
import java.util.Scanner;
class Girl{
private String name;
private int heigh,age;
private String call;
Girl(String name,int heigh,int age,String call){
this.name = name;
this.heigh = heigh;
this.age = age;
this.call = call;
}
//判断是否重复
public boolean repeat(Girl g) {
int a = name.compareTo(g.getName());
int b = 0;
if(g.getHeigh() == heigh) {
b = 1;
}
int c = 0;
if(g.getAge() == age) {
c = 1;
}
int d = call.compareTo(g.getCall());
if(a == 0 && b == 1 && c == 1 && d == 0) {
return true; //重复
}
else {
return false;
}
}
public int getHeigh() {
return heigh;
}
public int getAge() {
return age;
}
public String getName() {
return name;
}
public String getCall() {
return call;
}
}
public class Main {
public static void main(String args[]) {
Scanner input = new Scanner(System.in);
while(input.hasNext()) {
int t = input.nextInt();
int a,b,c,d;
a = input.nextInt();
b = input.nextInt();
c = input.nextInt();
d = input.nextInt();
Girl[] girl = new Girl[t+9];
int k = 0;
for(int i = 0;i < t;i++) {
String name = input.next();
int heigh = input.nextInt();
int age = input.nextInt();
String call = input.next();
Girl cc = new Girl(name,heigh,age,call);
int flag = 0;
for(int j = 0;j < k;j++) {
if(girl[j].repeat(cc)) { //若有重复
flag = 1;
}
}
if(flag == 0) {
if((cc.getHeigh() >= a && cc.getHeigh() <= b) && (cc.getAge() >= c && cc.getAge() <= d)) {
girl[k++] = cc;
}
}
}
for(int i = 0;i < k-1;i++) {
for(int j = 0;j < k-i-1;j++) {
if(girl[j].getHeigh() > girl[j+1].getHeigh()) {
Girl temp = girl[j];
girl[j] = girl[j+1];
girl[j+1] = temp;
}
else if(girl[j].getHeigh() == girl[j+1].getHeigh()) {
if(girl[j].getAge() < girl[j+1].getAge()) {
Girl temp = girl[j];
girl[j] = girl[j+1];
girl[j+1] = temp;
}
}
}
}
System.out.println(k);
for(int i = 0;i < k;i++) {
System.out.println(girl[i].getName()+" "+girl[i].getHeigh()+" "+girl[i].getAge()+" "+girl[i].getCall());
}
}
}
}