blJS

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

struct stu{
    string name;
    int score[3];
    int sum;
    double avg;
    bool flag;
};

bool cmp(stu &s1, stu &s2)
{
    return s1.avg > s2.avg;
}

void print(stu &s)
{
    cout << s.name << " " << s.score[0] << " " << s.score[1] << " " << s.score[2] << endl;
}

int main(void)
{
    int n;
    cin >> n;
    vector<stu> v(n);
    for(int i = 0; i < n; i++)
    {
        cin >> v.at(i).name;
        cin >> v.at(i).score[0] >> v.at(i).score[1] >> v.at(i).score[2] >> v.at(i).sum;
        if(v.at(i).score[0] < 60 || v.at(i).score[1] < 60 || v.at(i).score[2] < 60)
        {
            v.at(i).flag = true;
        }else{
            v.at(i).flag = false;
        }
        v.at(i).avg = v.at(i).sum / 3.0;
    }
    for(int i = 0; i < v.size(); i++)
    {
        if(v.at(i).flag == true)
        {
            cout << "*[" << v.at(i).name << "]" << " " << v.at(i).score[0]
                << " " << v.at(i).score[1] << " " << v.at(i).score[2] << " " << v.at(i).sum << endl;
        }
    }

    sort(v.begin(), v.end(), cmp);
    for_each(v.begin(), v.end(), print);

    return 0;
}
发布了125 篇原创文章 · 获赞 6 · 访问量 5199

猜你喜欢

转载自blog.csdn.net/weixin_42067873/article/details/101773399
今日推荐