import java.io.*;
public class Xueshengchengjipaixv
{
public static void main(String[] args)
{
int m=0;
try{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw=new BufferedWriter(new FileWriter("d:\\a.txt"));
String s;
while(true){
System.out.print("输入姓名:");
s=br.readLine();
if(s.length()==0) break;
bw.write(s);
bw.newLine();
System.out.print("输入学号:");
s=br.readLine();
bw.write(s);
bw.newLine();
System.out.print("输入成绩:");
s=br.readLine();
bw.write(s);
bw.newLine();
m++;
}
br.close();
bw.close();
String a[]=new String[m];
int b[]=new int[m];
int c[]=new int[m];
int d[]=new int[m];
BufferedReader bf=new BufferedReader(new FileReader("d:\\a.txt"));
int n=0;
while(true){
String ss=bf.readLine();
if(ss==null)
break;
a[n]=ss;
b[n]=Integer.parseInt(bf.readLine());
c[n]=Integer.parseInt(bf.readLine());
n++;}
bf.close();
int i,j,temp;
for(i=0;i<m;i++)
{
d[i]=i;
}
for(i=0;i<m-1;i++)
{
for(j=0;j<m-1;j++)
{
if(c[j]<c[j+1])
{
temp=c[j];
c[j]=c[j+1];
c[j+1]=temp;
temp=d[j];
d[j]=d[j+1];
d[j+1]=temp;
}
}
}
BufferedWriter bw1=new BufferedWriter(new FileWriter("d:\\b.txt"));
for(i=0;i<m;i++)
{
bw1.write(a[d[i]]+" "+String.valueOf(b[d[i]])+" "+String.valueOf(c[i]));
bw1.newLine();
}
bw1.close();
}
catch (FileNotFoundException fe)
{ System.out.println(fe.toString());}
catch (IOException ie)
{ System.out.println(ie.toString());}
}
}
评论