谁拿了最多奖学金——NOIP 2005 提高组

谁拿了最多奖学金——NOIP 2005 提高组_第1张图片

谁拿了最多奖学金——NOIP 2005 提高组_第2张图片

 输入样例:

4
YaoLin 87 82 Y N 0
ChenRuiyi 88 78 N Y 1
LiXin 92 88 N N 0
ZhangQin 83 87 Y N 1

输出样例:

ChenRuiyi
9000
28700

 谁拿了最多奖学金——NOIP 2005 提高组_第3张图片  

这道题用结构体做对吧

#include 
using namespace std;
class student{
    public:
        string name;
        int FG_average,  CReview_results;
        char SCadre, Swest;
        int paper, num;
        int money = 0;
};
class __Final__ : public student{ // 如果不知道可以关注博客在“类与结构体6”详细讲了关于继承的知识点
    public:
        void getstudent(string Tname,int TFG_average,int TCReview_results,char TSCadre,char TSwest,int Tpaper, int Tnum){
            name=Tname,FG_average=TFG_average,CReview_results=TCReview_results,SCadre=TSCadre,Swest=TSwest,paper=Tpaper,num=Tnum;
        }
        void getLevel1(__Final__ &Student){
            if(Student.FG_average > 80 && Student.paper >= 1) Student.money += 8000;
        }
        void getLevel2(__Final__ &Student){
            if(Student.FG_average > 85 && Student.CReview_results > 80) Student.money += 4000;
        }
        void getLevel3(__Final__ &Student){
            if(Student.FG_average > 90) Student.money += 2000;
        }
        void getLevel4(__Final__ &Student){
            if(Student.Swest == 'Y' && Student.FG_average > 85) Student.money += 1000;
        }
        void getLevel5(__Final__ &Student){
            if(Student.SCadre == 'Y' && Student.CReview_results > 80) Student.money += 850;
        }
        void get_money(__Final__ &Student){
            getLevel1(Student);
            getLevel2(Student);
            getLevel3(Student);
            getLevel4(Student);
            getLevel5(Student);
        }
        int getMoney(__Final__ &Student) {
            return Student.money;
        } 
        string getName(__Final__ &Student){
            return Student.name;
        }
        bool operator< (const __Final__ &Student)const{
            if(Student.money != money) return Student.money > money;
            else return Student.num < num;
        }
        friend void CPU(); // 如果不知道可以在类与结构体中找一下,有关于友元函数的详细解释
};
void CPU(){
	int n;
    cin >> n;
    vector<__Final__> Student(n);
    for(int i = 0; i < n; i++){
        string Tname;
        int TFG_average,TCReview_results;
        char TSCadre,TSwest;
        int Tpaper,Tnum = i + 1;
        cin >> Tname >> TFG_average >> TCReview_results >> TSCadre >> TSwest >> Tpaper;
        Student[i].getstudent(Tname,TFG_average,TCReview_results,TSCadre,TSwest,Tpaper,Tnum);
        Student[i].get_money(Student[i]);
    }
    sort(Student.begin(),Student.end());
    cout<

如果觉得这个版本太难了,就看一下下面这个↓

#include 
using namespace std;
class student{
    private:
        string name;
        int FG_average,  CReview_results;
        char SCadre, Swest;
        int paper, num;
        int money = 0;
    public:
        void getstudent(string Tname,int TFG_average,int TCReview_results,char TSCadre,char TSwest,int Tpaper, int Tnum){
            name=Tname,FG_average=TFG_average,CReview_results=TCReview_results,SCadre=TSCadre,Swest=TSwest,paper=Tpaper,num=Tnum;
        }
        void getLevel1(student &Student){
            if(Student.FG_average > 80 && Student.paper >= 1) Student.money += 8000;
        }
        void getLevel2(student &Student){
            if(Student.FG_average > 85 && Student.CReview_results > 80) Student.money += 4000;
        }
        void getLevel3(student &Student){
            if(Student.FG_average > 90) Student.money += 2000;
        }
        void getLevel4(student &Student){
            if(Student.Swest == 'Y' && Student.FG_average > 85) Student.money += 1000;
        }
        void getLevel5(student &Student){
            if(Student.SCadre == 'Y' && Student.CReview_results > 80) Student.money += 850;
        }
        void get_money(student &Student){
            getLevel1(Student);
            getLevel2(Student);
            getLevel3(Student);
            getLevel4(Student);
            getLevel5(Student);
        }
        int getMoney(student &Student) {
            return Student.money;
        } 
        string getName(student &Student){
            return Student.name;
        }
        bool operator< (const student &Student)const{
            if(Student.money != money) return Student.money > money;
            else return Student.num < num;
        }
};
int main(){
    int n;
    cin >> n;
    vector Student(n);
    for(int i = 0; i < n; i++){
        string Tname;int TFG_average,TCReview_results;char TSCadre,TSwest;int Tpaper,Tnum = i + 1;
        cin >> Tname >> TFG_average >> TCReview_results >> TSCadre >> TSwest >> Tpaper;
        Student[i].getstudent(Tname,TFG_average,TCReview_results,TSCadre,TSwest,Tpaper,Tnum);
        Student[i].get_money(Student[i]);
    }
    sort(Student.begin(),Student.end());
    cout<

你可能感兴趣的:(算法,c++,数据结构)