前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >HDU 1084 What Is Your Grade?(排序)

HDU 1084 What Is Your Grade?(排序)

作者头像
Enterprise_
发布2019-02-21 17:35:23
4350
发布2019-02-21 17:35:23
举报
文章被收录于专栏:小L的魔法馆
  • 题目在这里:1084
  • 题目描述: “Point, point, life of student!” This is a ballad(歌谣)well known in colleges, and you must care about your score in this exam too. How many points can you get? Now, I told you the rules which are used in this course. There are 5 problems in this final exam. And I will give you 100 points if you can solve all 5 problems; of course, it is fairly difficulty for many of you. If you can solve 4 problems, you can also get a high score 95 or 90 (you can get the former(前者) only when your rank is in the first half of all students who solve 4 problems). Analogically(以此类推), you can get 85、80、75、70、65、60. But you will not pass this exam if you solve nothing problem, and I will mark your score with 50. Note, only 1 student will get the score 95 when 3 students have solved 4 problems. I wish you all can pass the exam! Come on!
  • 题意分析: 有五道题,满分是100分,做出5道就是100,4道90,3道80,2道70,1道60,一道都没做出来就是50分。如果你处于和你做出同样多的题目数的人的前一半,那么就可以多拿5分,做出5道题和0道题的同学不在此列。
  • 我的思路: 记录时间,按照时间降序排列,但是要按照原来的顺序输出分数,所以需要一个数组来记录原来的顺序,不能在原来的数据上直接进行排序,一开始我没有考虑到这个,吃了WA。还有一个问题,考虑到如果是只有一个人,或者好几个人花同样的时间做出了同样的时间,后者可以按照原来的规则来,一个人就再写一个判断就行。 虽然看discuss,好像没有这样的数据。w(゚Д゚)w 最后采用一个二维数组来存储做同样多道题的人数和记录原本的顺序,a[5][105], 比如a[1][0],就是只做出一道题的人数,假如有5个人,那么a[1][1]–a[1][5]就可以保存他们原来的顺序。
  • 完整代码
代码语言:javascript
复制
#include<iostream>
#include<string.h>

using namespace std;
typedef struct student
{
    char time[15];          //消耗时间
    int score;              //分数
}student;
student stu[105];
int main()
{
    int i, j, k, n, temp, tt;
    int a[5][105];              //用于记录做题人数和做题顺序
    while (cin >> n)      //学生数目n
    {
        if (n <= 0) break;
        memset(a, 0, sizeof(int) * 5 * 105);    //归零
        for (i = 1; i <= n; i++)
        {
            cin >> temp >> stu[i].time;     //题目数以及消耗时间
            stu[i].score = 50 + temp * 10;
            if (temp>0 && temp<5)
            {
                a[temp][0]++;               //做出同样题目数目的人
                tt = a[temp][0];            //为了标记顺序
                a[temp][tt] = i;            //记录做出这道题的人的顺序
            }
        }
        for (i = 1; i<5; i++)           //做出题目数目从1到4
        {
            for (j = 2; j <= a[i][0]; j++)
            {
                for (k = 2; k <= a[i][0] + 2 - j; k++)
                {
                    if (strcmp(stu[a[i][k - 1]].time, stu[a[i][k]].time) > 0)       //按照时间大小降序排列
                    {
                        swap(a[i][k - 1], a[i][k]);
                    }
                }
            }
            for (j = 1; j <= a[i][0] / 2; j++)
                stu[a[i][j]].score += 5;
        }
        for (i = 1; i <= n; i++)
            cout << stu[i].score << endl;
        cout << endl;
    }
    return 0;
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2017年09月01日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档