时长两年半的某 2021-12-16 18:27 采纳率: 70.6%
浏览 38
已结题

一到简单的oj提母靠

img

img

  • 写回答

2条回答 默认 最新

  • 索利亚噶通 2021-12-16 19:08
    关注

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

    #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();
        }
    }
    
    
     
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 12月24日
  • 已采纳回答 12月16日
  • 创建了问题 12月16日

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测