一到简单的oj提母靠

img

img

这个空行那里注意下(有用请采纳)

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

class Stu{
private:
    string name;
    int programScore;
    int introductionScore;
    int englishScore;

public:
    Stu(string name, int programScore, int introductionScore, int englishScore);
    void showInfo();
    int getTotalScore() const;
    int getProgramScore() const;
    int getIntroductionScore() const;
};

Stu::Stu(string name, int programScore, int introductionScore, int englishScore){
    this->name = name;
    this->programScore = programScore;
    this->introductionScore = introductionScore;
    this->englishScore = englishScore;
}

void Stu::showInfo(){
    cout << this->name << " ";
    cout << getTotalScore() << " ";
    cout << this->programScore << " ";
    cout << this->introductionScore << " ";
    cout << this->englishScore << endl;
}


int Stu::getTotalScore() const{
    return this->programScore + this->introductionScore + this->englishScore;
}

int Stu::getIntroductionScore() const{
    return this->introductionScore;
}

int Stu::getProgramScore() const{
    return this->programScore;
}

bool cmp(const Stu& stu1, const Stu& stu2){
    if (stu1.getTotalScore() != stu2.getTotalScore())  // 总分不等的情况下 
        return stu1.getTotalScore() > stu2.getTotalScore();
    
    if (stu1.getProgramScore() != stu2.getProgramScore())  // C语言成绩不等的情况下 
        return stu1.getProgramScore() > stu2.getProgramScore();
    
    return stu1.getIntroductionScore() > stu2.getIntroductionScore();
    
}


int main(){
    int N, programScore, introductionScore, englishScore;
    string name;
    vector<Stu> stuScore; // 存储所有人的分数 
    
    while(cin >> N){
        
        for (int i = 0; i < N; i++){
            cin >> name >> programScore >> introductionScore >> englishScore;
            Stu stu = Stu(name, programScore, introductionScore, englishScore);
            stuScore.push_back(stu);
        }
        
        sort(stuScore.begin(), stuScore.end(), cmp);
        
        for(vector<Stu>::iterator it = stuScore.begin(); it != stuScore.end(); it++){
            it->showInfo();
        }
        cout << endl;
        
        stuScore.clear();
    }
}


 


#include <iostream>
#include <algorithm>
using namespace std;
struct Student
{
    char name[20];
    int C,Computer,English,total;
};
bool comparison(struct Student a,struct Student b){
    if(a.total > b.total){
        return true;
    }else{
        if(a.total == b.total){
            if(a.C > b.C){
                return true;
            }else{
                if(a.C == b.C){
                    return a.Computer > b.Computer;
                }else{
                    return false;
                }
            }
        }else{
            return false;
        }
    }
}
int main()
{
    int N;
    while(1){
        cin >> N;
        struct Student scores[N];
        for(int i = 0;i < N;i++){
            cin >> scores[i].name >> scores[i].C >> scores[i].Computer >> scores[i].English;
            scores[i].total = scores[i].C + scores[i].Computer + scores[i].English;
        }
        sort(scores,scores + N,comparison);
        for(int i = 0;i < N;i++){
            cout << scores[i].name << " " << scores[i].total << " " << scores[i].C << " " << scores[i].Computer << " " << scores[i].English << endl;
        }
    }
    return 0;
}