Description
单身贵族C~K已经受够了独自一人的生活,他想要找一个女朋友来陪他一起学习,因此他面向全国发了一条招亲的通知。
因为CK非常的优秀,因此全国各地很多妹子都发来了自己的报名表,CK的手下DaYu帮他整理这些报名表,每收到一份新的报名表,就会把这份报名表放在最上面。
为了公平起见,CK决定按照妹子提交的顺序来查看这些报名表,而且CK不吃香菜,也不喜欢吃香菜的人,因此他不想看到喜欢吃香菜的人的报名表。而且有的妹子十分心急,提交了多份报名表,应该去掉这些重复的报名表。
C~K要求DaYu去重新整理排序一遍这些报名表,但是报名表实在太多,DaYu整理不过来,因此DaYu跑来求助你。
Input
妹子提交的报名表,内容分别为妹子姓名、妹子自我介绍,以及妹子是否喜欢吃香菜(True or False),同样的报名表只保留第一次出现的那份。
Output
C~K期望看到的报名表序列
Sample
Input
凤姐 我爱你 False
芙蓉 我想要和你在一起 False
dayu 也许这就是爱情 False
奶茶 呵呵 True
芙蓉 我想要和你在一起 False
Output
dayu 也许这就是爱情 False
芙蓉 我想要和你在一起 False
凤姐 我爱你 False
Hint
当 reader.hasNext() == false 的时候,输入结束
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
class Girl {
String name;
String introduce;
String xiangcai;
public Girl(String name, String introduce, String xiangcai) {
super();
this.name = name;
this.introduce = introduce;
this.xiangcai = xiangcai;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((introduce == null) ? 0 : introduce.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((xiangcai == null) ? 0 : xiangcai.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 (introduce == null) {
if (other.introduce != null)
return false;
} else if (!introduce.equals(other.introduce))
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
if (xiangcai == null) {
if (other.xiangcai != null)
return false;
} else if (!xiangcai.equals(other.xiangcai))
return false;
return true;
}
@Override
public String toString() {
return name + " " + introduce + " " + xiangcai;
}
}
public class Main {
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
List<Girl> list = new ArrayList<Girl>();
while (reader.hasNext() && reader.hasNext() != false) {
String name = reader.next();
String introduce = reader.next();
String xiangcai = reader.next();
if (xiangcai.equals("False")) {
Girl girl = new Girl(name, introduce, xiangcai);
if (!list.contains(girl))
list.add(girl);
}
}
Collections.reverse(list);//逆置
for(Girl girl : list) {
System.out.println(girl);
}
reader.close();
}
}