日期:2014-05-20 浏览次数:20899 次
package com.briup.test08;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
public class Test3{
public static void main(String[] args) {
List list=new ArrayList<User>();
Map map=new HashMap<Integer, User>();
for(int i=0;i<4;i++)
{
Scanner input=new Scanner(System.in);
String str=input.next();
String[] s=str.split(",");
User u=new User();
u.setName(s[0]);
u.setShuxue(s[1]);
u.setYingyu(s[2]);
u.setYuwen(s[3]);
list.add(u);
}
int len=list.size();
for(int j=1;j<=len;j++){
int max=0;
for(int i=list.size()-1;i>=0;i--){
User u=(User) list.get(i);
int m=Integer.parseInt(u.getNum());
if(m>max){
max=m;
map.put(j, u);//排名和对象产生键值对的关系
}
}
list.remove(j);//删除每轮遍历最大的那个
}
//最后把map用objectOutStream的方式存储到文件里就行了,这个就不写了。代码我没时间调试了,有急事忙别的,你试试看
//有问题留言
}
}
class User{
String name;
String shuxue;
String yingyu;
String yuwen;
String num;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getShuxue() {
return shuxue;
}
public void setShuxue(String shuxue) {
this.shuxue = shuxue;
}
public String getYingyu() {
return yingyu;
}
public void setYingyu(String yingyu) {
this.yingyu = yingyu;
}
public String getYuwen() {
return yuwen;
}
public void setYuwen(String yuwen) {
this.yuwen = yuwen;
}
public User(String name, String shuxue, String yingyu, String yuwen) {
super();
this.name = name;
this.shuxue = shuxue;
this.yingyu = yingyu;
this.yuwen = yuwen;
}
public void setNum(){
this.num=this.shuxue+this.yingyu+this.yuwen;
}
public User() {
super();
// TODO Auto-generated constructor stub
}
public String getNum() {
return num;
}
public void setNum(String num) {
this.num = num;
}
}