HDU/HDOJ 1084 What Is Your Grade?

题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1084

水题,就是用sort或qsort比较。

不过这里有一点要注意,在比较时间时,可以统一转换成按s来比较。

AC代码,写的很水很烂,自己都觉得晕了。。。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include <iostream>
#include <algorithm>
using namespace std;
 
typedef struct time{
    int h, m, s;
    int tot;
}time;
 
typedef struct stu{
    int p;
    time t;
    int id;
    int sco;
}stu;
 
stu ss[105], ss2[105];
int n;
 
bool cmp (stu e1, stu e2 )
{
    if(e1.p != e2.p)
        return e1.p > e2.p;
    else
        return e1.t.tot < e2.t.tot;
}
 
bool cmp2(stu e1, stu e2)
{
    return e1.id < e2.id;
}
 
int main()
{
    //freopen("input.txt", "r", stdin);
    //bool flag = 0;
 
    while(cin >> n && n != -1)
    {
        //if(flag == 1)
        //    cout << endl;
        //flag = 1;
        int c[6];  // 1, 2, 2, 4;
        memset(c, 0, sizeof(c));
        int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
        int cnt = 0;
        for(int i=0; i<n; ++i)
        {
            ss[i].id = i+1;
            scanf("%d", &ss[i].p);
            scanf("%d:%d:%d", &ss[i].t.h, &ss[i].t.m, &ss[i].t.s);
            ss[i].t.tot = ss[i].t.h*3600 + ss[i].t.m*60 + ss[i].t.s;
        }
        sort(ss, ss+n, cmp);
        for(int i=0; i<n; ++i)
        {
            //cout << ss[i].p << "    " << ss[i].t.h << " " << ss[i].t.m << " " << ss[i].t.s << endl;
            c[ss[i].p]++;
        }
        for(int i=0; i<n; ++i)
        {
            if(ss[i].p == 5)
                ss[i].sco = 100;
            else if(ss[i].p == 4)
            {
                ++c4;
                if(c4 <= c[4]/2)
                    ss[i].sco = 95;
                else
                    ss[i].sco = 90;
            }
            else if(ss[i].p == 3)
            {
                ++c3;
                if(c3 <= c[3]/2)
                    ss[i].sco = 85;
                else
                    ss[i].sco = 80;
            }
            else if(ss[i].p == 2)
            {
                ++c2;
                if(c2 <= c[2]/2)
                    ss[i].sco = 75;
                else
                    ss[i].sco = 70;
            }
            else if(ss[i].p == 1)
            {
                ++c1;
                if(c1 <= c[1]/2)
                    ss[i].sco = 65;
                else
                    ss[i].sco = 60;
            }
            else
                ss[i].sco = 50;
        }
        sort(ss, ss+n, cmp2);
        for(int i=0; i<n; ++i)
        {
            //cout << ss[i].p << "    " << ss[i].t.h << " " << ss[i].t.m << " " << ss[i].t.s << endl;
            //c[ss[i].p]++;
        }
        for(int i=0; i<n; ++i)
            cout << ss[i].sco << endl;
        cout << endl;
    }
}

发布者

Tanky Woo

Tanky Woo,[个人主页:https://tankywoo.com] / [新博客:https://blog.tankywoo.com]

发表评论

电子邮件地址不会被公开。 必填项已用*标注