Untitled

 avatar
unknown
plain_text
4 years ago
2.3 kB
67
Indexable
Tính điểm trung bình/Main.java
import java.util.*;
import java.io.*;

public class Main{
    public static void main(String[] args) throws IOException,ClassNotFoundException,FileNotFoundException {
        Scanner sc = new Scanner(new File("BANGDIEM.in"));
        int t = Integer.parseInt(sc.nextLine());
        ArrayList<Sv> res = new ArrayList<>();
        for(int i = 1; i <= t; i++ ){
            res.add(new Sv(i, sc.nextLine(), Float.parseFloat(sc.nextLine()), Float.parseFloat(sc.nextLine()), Float.parseFloat(sc.nextLine())));
        }
        res.sort(null);
        int xh = 1;
        res.get(0).setTt(xh);
        for(int i = 1; i < res.size(); i++){
            if(res.get(i).getDiem() < res.get(i-1).getDiem()){
                res.get(i).setTt(i+1);
            }
            else res.get(i).setTt(res.get(i-1).getXh());
        }
        for(Sv a: res){
            System.out.println(a);
        }
    }
}

Tính điểm trung bình/Sv.java
public class Sv implements Comparable<Sv> {
    private String id,name;
    private Float diem;
    private Integer xh;
    public Sv(int id, String name, Float d1, Float d2, Float d3){
        this.id = String.format("SV%02d", id);
        this.name = chuanhoa(name);
        this.diem = (d1*3) + (d2*3) + (d3*2);
        // this.diem = (float) ( Math.ceil(this.diem * 100d)/100);
        this.diem = (float)Math.round(this.diem/ 8d * 100d) / 100;
    }
     private String chuanhoa(String a){
        String res="";
        String[] tmp = a.trim().toLowerCase().split("\\s+");
        for(String i : tmp){
            String tmp3 = i.toUpperCase();
            char x = tmp3.charAt(0);
            String tmp2 = "";
            tmp2 =tmp2 + x ;
            for(int j = 1; j < i.length(); j++) tmp2= tmp2 + i.charAt(j) ;
            res = res + tmp2 + " ";
            this.xh= 0;
        }
        return res;
    }

    public void setTt(int xh){
        this.xh = xh;
    }
    public int getXh(){
        return this.xh;
    }
    public Float getDiem(){
        return this.diem;
    }
    public int compareTo(Sv a){
        return this.diem.compareTo(a.diem) == 0 ? this.id.compareTo(a.id) : - this.diem.compareTo(a.diem);
    }

    public String toString(){
        return id + " " + name  + diem + " " + xh;
    }
}
Editor is loading...