HDU What Is Your Grade?(简单题)

感受:

这道题其实思路其实很简单,按道理说做起来应该可以直接过,可是我依旧调了一个多小时。。。

首先,细节很重要!!!

排序时不小心把return a.second < return b.second,写成了return a.second < return a.second。。。刚开始一直找不到错误,然后就自己想测试数据去不断的测试。。。

额外测试数据:

9
5 06:30:17
4 07:31:27
4 07:12:12
4 05:23:13
4 05:23:14
4 05:23:12
2 04:12:11
3 04:11:11
0 00:00:00
-1

其次,审题要认真!!!

审题不认真,输出结果是按输入的顺序来输出的,而不是按成绩的由高到低,在刚开始审题出现偏差,导致思路直接跑偏了。。。后来就为了AC而又不想重新写一份,于是就又给结构体添加了一个属性,进行了恢复输入顺序的第二次排序,导致代码非常混乱。。。

  1 #include <cstdio>
  2 #include <cstring>
  3 #include <iostream>
  4 #include <algorithm>
  5 using namespace std;
  6 
  7 #define STU_NUM 110
  8 #define TIME 10
  9 #define QUE_NUM 10
 10 
 11 struct Info
 12 {
 13     int num;
 14     int hour;
 15     int minute;
 16     int second;
 17 
 18     int no; //同题数排名编号
 19     int score;
 20     int id;
 21 }info[STU_NUM];
 22 
 23 bool time_cpy(Info a, Info b)
 24 {
 25     if (a.hour == b.hour)
 26     {
 27         if (a.minute == b.minute)
 28         {
 29             return a.second < b.second;
 30         }
 31         return a.minute < b.minute;
 32     }
 33     return a.hour < b.hour;
 34 }
 35 
 36 bool cmp(Info a, Info b)
 37 {
 38     if (a.num == b.num)
 39         return time_cpy(a, b);
 40     return a.num > b.num;
 41 }
 42 
 43 bool cmp_2(Info a, Info b)
 44 {
 45     return a.id < b.id;
 46 }
 47 
 48 int main(void)
 49 {
 50     int n;
 51     while (scanf("%d", &n) && n != -1)
 52     {
 53         memset(info, 0, sizeof(info));
 54 
 55         char time[TIME] = {0};
 56         int tmp[QUE_NUM] = {0};
 57 
 58         for (int i = 0; i < n; i++)
 59         {
 60             scanf("%d%s", &info[i].num, time);
 61             sscanf(time, "%d:%d:%d", &info[i].hour, &info[i].minute, &info[i].second);
 62             info[i].id = i;
 63         }
 64         sort(info, info + n, cmp);
 65         for (int i = 0; i < n; i++)
 66         {
 67             tmp[info[i].num]++;
 68             info[i].no = tmp[info[i].num];
 69         }
 70         for (int i = 0; i < n; i++)
 71         {
 72             if (info[i].num == 5)
 73                 info[i].score = 100;
 74             else if (info[i].num == 4)
 75                 info[i].score = (info[i].no <= (tmp[info[i].num] / 2) || tmp[info[i].num] == 1) ? 95 : 90;
 76             else if (info[i].num == 3)
 77                 info[i].score = (info[i].no <= (tmp[info[i].num] / 2) || tmp[info[i].num] == 1) ? 85 : 80;
 78             else if (info[i].num == 2)
 79                 info[i].score = (info[i].no <= (tmp[info[i].num] / 2) || tmp[info[i].num] == 1) ? 75 : 70;
 80             else if (info[i].num == 1)
 81                 info[i].score = (info[i].no <= (tmp[info[i].num] / 2) || tmp[info[i].num] == 1) ? 65 : 60;
 82             else
 83                 info[i].score = 50;
 84         }
 85 
 86         sort(info, info + n, cmp_2);
 87 
 88         for (int i = 0; i < n; i++)
 89         {
 90             printf("%d\n", info[i].score);
 91         }
 92 
 93 //        for (int i = 0; i < n; i++)
 94 //        {
 95 //            cout << "-------------------------------" <<endl;
 96 //            cout << "===num:" << info[i].num << endl;
 97 //            cout << "===hour:" << info[i].hour << endl;
 98 //            cout << "===minute:" << info[i].minute << endl;
 99 //            cout << "===second:" << info[i].second << endl;
100 //            cout << "===no:" << info[i].no << endl; //同题数排名编号
101 //            cout << "===score:" << info[i].score << endl;
102 //            cout << "===id:" << info[i].id << endl;
103 //        }
104 
105         printf("\n");
106     }
107     return 0;
108 }

 

posted @ 2018-07-17 21:06  Feng_Change  阅读(148)  评论(0编辑  收藏  举报