#include <bits/stdc++.h>
using namespace std;
class SV{
    private:
        char msv[15],nganh[20];
        string ten;
        string xep;
        int ng,th,nam;
        float toan,van,tin,tong;
    public:
        void nhap(){
            cout<<"Nhap ho ten: "; getline(cin,ten);
            cout<<"Ma sinh vien: "; cin.getline(msv,15);
            cout<<"Nganh hoc: "; cin.getline(nganh,20);
            cout<<"Ngay sinh(date): "; cin >> ng >> th >> nam;
            while(ng > 31){
                cout<<"Moi nhap lai ngay: "; cin>>ng;
            }
            while(th > 12){
                cout<<"Moi nhap lai thang: "; cin>>th;
            }
            while(nam > 2024){
                cout<<"Moi nhap lai nam: "; cin>>nam;
            }
            cout<<"Nhap diem toan: "; cin >> toan;
            cout<<"Nhap diem van: "; cin >> van;
            cout<<"Nhap diem tin: "; cin >> tin;
            cin.ignore();
            cout<<endl;
            
        }
        void tinh(){
            tong = (toan*4 + van*4 + tin*2)/10;
            if(tong >= 9){
                xep = "Xuat sac";
            }else
                if(tong >= 7.5){
                    xep = "Gioi";
                }else
                    if(tong >= 6){
                        xep = "Kha";
                   }else
                    if(tong >= 4){
                        xep = "Trung binh";
                    }else
                        if(tong < 4){
                            xep = "Yeu";
                        }
                
        }

        void xuat(){
            cout<<setw(20)<<left<<ten
            <<setw(15)<<left<<msv;
            if(ng<10) cout<<"0"<<ng<<"/";
                else cout<<ng<<"/";
            if(th < 10) cout<<"0"<<th<<"/";
                else cout<<nam<<"/";
            cout<<setw(10)<<left<<nam
            <<setw(10)<<left<<nganh
            <<setw(13)<<left<<tong
            <<setw(10)<<left<<xep<<endl;
        }
        float gettong(){
            return this->tong;
        }
        int getten(){
            return this->ten.size();
        }
};

bool cmp(SV a, SV b){
    if(a.gettong() < b.gettong()) return a.gettong();
        // if(a.gettong() > b.gettong())  return b.gettong();
        // else{
    if(a.gettong() == b.gettong()){
        if(a.getten() < b.getten()) return a.getten();
    }
        //         else return b.getten();
        //     }
        // }
}
int main(){
    int n;
    cout<<"Nhap so luong sv: "; cin >> n;
    SV sv[n];
    cin.ignore();
    for(int i = 0; i < n; i++){
        sv[i].nhap();
        sv[i].tinh();
    }
    sort(sv,sv+n,cmp);
    cout<<endl<<"--------\n";
    cout<<setw(20)<<left<<"Ho va ten"
    <<setw(15)<<left<<"Ma sinh vien"
    <<setw(16)<<left<<"Ngay sinh"
    <<setw(10)<<left<<"Nganh"
    <<setw(13)<<left<<"Diem tong"
    <<setw(10)<<left<<"Xep loai"<<endl;
    for(int i = 0; i < n; i++){
        sv[i].xuat();
    }

}