<p> <no>1</no> <lw>140</lw> <bw>54</bw> </p> <p> <no>2</no> <lw>155</lw> <bw>53</bw> </p> <p> <no>3</no> <lw>140</lw> <bw>42</bw> </p> <p> <no>4</no> <lw>140</lw> <bw>55</bw> </p> <p> <no>5</no> <lw>130</lw> <bw>46</bw> </p>
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
public class forth {
public static void main(String[] args) {
ArrayList<Person> list=new ArrayList<Person>();
try {
FileReader fr=new FileReader("c:\\data.txt");
BufferedReader br=new BufferedReader(fr);
String str=null;
int num=0;
int score=0;
int weight=0;
int i=0;
while((str=br.readLine())!=null)
{
i++;
if(i%5==2)
{
str=str.trim().substring(4,str.length()-5);
num=Integer.parseInt(str);
str=br.readLine().trim();
str=str.substring(4,str.length()-5);
score=Integer.parseInt(str);
i++;
str=br.readLine().trim();
str=str.substring(4,str.length()-5);
weight=Integer.parseInt(str);
i++;
Person p=new Person(num,score,weight);
list.add(p);
}
else
continue;
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
Person[] plist=new Person[list.size()];
list.toArray(plist);
Arrays.sort(plist);
for(int i=0;i<plist.length;i++)
{
System.out.print(plist[i].getNum()+". " +plist[i].getScore()+" "+plist[i].getWeight()+"\n\r");
}
}
}
class Person implements Comparable<Person>{
private int num;
private int weight;
private int score;
public Person(int num,int score,int weight){
this.num=num;
this.score=score;
this.weight=weight;
}
@Override
public int compareTo(Person other) {
if(this.score>other.score)return -1;
else if(this.score<other.score) return 1;
else
return this.weight>other.weight?1:-1;
}
public int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
}
public int getWeight() {
return weight;
}
public void setWeight(int weight) {
this.weight = weight;
}
public int getScore() {
return score;
}
public void setScore(int score) {
this.score = score;
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有