按绩点排名

Description:

有一些班级的学生需要按绩点计算并排名。每门课程的成绩只有在60分以上(含),才予以计算绩点。课程绩点的计算公式为: (课程成绩 – 50)÷10×学分数一个学生的总绩点为其所有课程绩点总和除以10。

Input:

输入数据中含有一些班级(≤20)。每个班级的第一行数据n(≤10),a1,a2,a3,…,an,表示该班级共有n门课程,每门课程的学分分别为a1,a2,a3,…,an;班级数据中的第二行数据为一个整数m(≤50),表示本班级有m个学生;班级数据接下去有m行对应m个学生数据;每行学生数据中的第一个为字串s1(s1中间没有空格),表示学生姓名,后面跟有n个整数s1,s2,s3,…,sn,表示该学生各门课程的成绩(0≤si≤100)。

Output:

以班级为单位输出各个学生按绩点分从大到小的排名。如果绩点分相同,则按学生名字的ASCII串值从小到大排名。每个班级的排名输出之前应先给出一行,描述班级序号“class #:”(#表示班级序号),班级之间应空出一行。排名时,每个学生占一行,列出名字和总绩点。学生输出宽度为10个字符,左对齐,在空出一格后列出总绩点。

Input Sample:

2
3 3 4 3
3
张三   89 62 71
Smith 98 50 80
王五   67 88 91

4 3 3 5 6
4
李四 90 80 90 85
张三 99 97 96 95
John 98 97 80 87
Mary 80 87 89 98

Output Sample:

Class 1:
王五     3.26
Smith      2.34
张三     2.28

Class 2:
张三     7.88
Mary       6.84
John       6.57
李四     6.20

代码如下:

#include<iostream>
#include<fstream>
#include<set>
#include<string>
#include<queue>
#include<set>
#include<iterator>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<numeric>
using namespace std;
class student
{
public:
    string name;
    double dig;
    bool operator < (const student& stu) const
    {
        if (stu.dig != dig)
        {
            return dig>stu.dig;
        }
        return name<stu.name;
    }
};
int main()
{
    #ifdef ONLINE_JUDGE
    #else
        freopen("D:\\in.txt", "r", stdin);
        freopen("D:\\out.txt", "w", stdout);
    #endif
        int classnum(0);//班级总数
        int coursenum(0);//课程总数
        int stunum(0);//学生总数
        string name;//学生的姓名
        int score(0);//学生的课程成绩
        vector<int> vxf;//学分向量
        vector<student> coll;//学生向量
        student stu;
        cin >> classnum;
        for (int k = 0; k < classnum;k++)
        {
            vxf.clear();
            coll.clear();
            coursenum = 0;
            stunum = 0;
            cin >> coursenum;
            int n;//学分
            for (int i = 0; i < coursenum; i++)
            {
                cin >> n;
                vxf.push_back(n);
            }
            cin >> stunum;
            for (int i = 0; i < stunum; i++)
            {
                double jidian = 0;
                cin >> name;
                for (int j = 0; j < coursenum; j++)
                {
                    cin >> score;
                    if (score < 60)
                    {
                        continue;
                    }
                    jidian += (double)(score - 50) / 10 * vxf.at(j);
                }
                stu.name = name;
                stu.dig = jidian/10;
                coll.push_back(stu);
            }
            sort(coll.begin(),coll.end());
            cout << (k ? "\n" : "");//处理每一个班,这个地方的思路要注意
            cout << "Class " << k + 1 << ":" << endl;
            for (vector<student>::iterator it = coll.begin(); it != coll.end(); it++)
            {
                //使用fixed,表明是定点输出
                //或用cout.precesion(n),来设定小数点后保留n位
                //输出时加“fixed”参数,表明是定点输出
                cout << fixed << setprecision(2);
                cout << left << setw(11);//此设置只能使用一次
                cout << (*it).name << (*it).dig << endl;
            }
        }
        return 0;
}

  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值