import java.util.*;
import java.io.*;
class Student
{
String name;
String sex;
String birthday;
}
public class Person
{
public static void main(String[] args)
{
FileInputStream fis=null;
Scanner sc=null;
FileWriter fw=null;
BufferedWriter bw=null;
try
{
fis=new FileInputStream("d:\\test1.txt");
sc=new Scanner(fis);
fw=new FileWriter("e:\\test2.txt");
bw=new BufferedWriter(fw);
List<Student> list=new ArrayList<Student>();
sc.nextLine();//讀文件的第壹行
while(sc.hasNext())
{
Student temp=new Student();
temp.name=sc.next();
temp.sex=sc.next();
temp.birthday=sc.next();
if(temp.sex.equals("女"))//只加性別為女的
{
list.add(temp);
}
}
Collections.sort(list, new Comparator<Student>()//按生日字符串的字典順序排序,生日從小到大
{
public int compare(Student o1,Student o2)
{
return o1.birthday.compareTo(o2.birthday);
}
});
bw.write("姓名 生日");
bw.newLine();
for(int i=0;i<list.size();i++)
{
Student temp=list.get(i);
bw.write(temp.name+" "+temp.birthday);
bw.newLine();//輸入換行符
Student temp1=list.get(i+1);
if(!temp.birthday.equals(temp1.birthday))//判斷是否有生日相同的
{
break;
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
try
{
bw.close();//關閉流
fis.close();
sc.close();
fw.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
}