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