亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

The Best Rank (25)(排名算法)

系統 1595 0

?

?

To evaluate the performance of our first year CS majored students, we consider their grades of three courses only: C - C Programming Language, M - Mathematics (Calculus or Linear Algebra), and E - English. At the mean time, we encourage students by emphasizing on their best ranks -- that is, among the four ranks with respect to the three courses and the average grade, we print the best rank for each student.

?

For example, The grades of C, M, E and A - Average of 4 students are given as the following:

?StudentID??C??M??E??A

310101?????98 85 88 90

310102?????70 95 88 84

310103?????82 87 94 88

310104?????91 91 91 91

?

?Then the best ranks for all the students are No.1 since the 1st one has done the best in C Programming Language, while the 2nd one in Mathematics, the 3rd one in English, and the last one in average.

?

Input

?

Each input file contains one test case. Each case starts with a line containing 2 numbers N and M (<=2000), which are the total number of students, and the number of students who would check their ranks, respectively. Then N lines follow, each contains a student ID which is a string of 6 digits, followed by the three integer grades (in the range of [0, 100]) of that student in the order of C, M and E. Then there are M lines, each containing a student ID.

?

Output

?

For each of the M students, print in one line the best rank for him/her, and the symbol of the corresponding rank, separated by a space.

?

The priorities of the ranking methods are ordered as A > C > M > E. Hence if there are two or more ways for a student to obtain the same best rank, output the one with the highest priority.

?

If a student is not on the grading list, simply output "N/A".

Sample Input

5 6

310101 98 85 88

310102 70 95 88

310103 82 87 94

310104 91 91 91

310105 85 90 90

310101

310102

310103

310104

310105

999999

?Sample Output

1 C

1 M

1 E

1 A

3 A

N/A

?

排名不應該只是簡單的排序算法:

比如說??100,100,99,……???得99分是人是 第二名,而不是第三名。

所以,應該先對分數進行排序,然后在更新名次,算法如下:

????????

? ??

      
         1
      
            SS[
      
        0
      
      ].ra=
      
        1
      
        //
      
      
        第一個肯定是第一名
      
      
         2
      
      
         3
      
      
        int
      
       count=
      
        1
      
      
        ;


      
      
         4
      
      
         5
      
      
        for
      
      (i=
      
        1
      
      ;i<n;i++
      
        )


      
      
         6
      
      
         7
      
      
                    {


      
      
         8
      
      
         9
      
      
        if
      
      (SS[i].A==SS[i-
      
        1
      
      ].A)
      
        //
      
      
        A為平均分
      
      
        10
      
      
        11
      
      
                          {


      
      
        12
      
      
        13
      
                             SS[i].ra=SS[i-
      
        1
      
      ].ra;
      
        //
      
      
        ra 平均分排名
      
      
        14
      
      
        15
      
                         count++;
      
        //
      
      
        如果分數相同,那么名次和前一個相同,計數器++
      
      
        16
      
      
        17
      
      
                          }


      
      
        18
      
      
        19
      
      
        else
      
      
        20
      
      
        21
      
      
                            {


      
      
        22
      
      
        23
      
                              SS[i].ra=SS[i-
      
        1
      
      ].ra+
      
        count;


      
      
        24
      
      
        25
      
                               count=
      
        1
      
      ;
      
        //
      
      
        計算器記得還原
      
      
        26
      
      
        27
      
      
                            }


      
      
        28
      
      
        29
      
                }
    

?

?

?

AC代碼:

?

        
            1
        
         #include <iostream>


        
            2
        
        
            3
        
         #include <algorithm>


        
            4
        
        
            5
        
         #include <
        
          string
        
        >


        
            6
        
        
            7
        
        
          using
        
        
          namespace
        
        
           std;


        
        
            8
        
        
            9
        
        
           10
        
        
           11
        
        
          struct
        
        
           stu


        
        
           12
        
        
           13
        
        
          {


        
        
           14
        
        
           15
        
        
          string
        
        
           ID;


        
        
           16
        
        
           17
        
        
          int
        
        
           A,C,M,E;


        
        
           18
        
        
           19
        
        
          int
        
        
           ra,rc,rm,re;


        
        
           20
        
        
           21
        
        
          };


        
        
           22
        
        
           23
        
        
           24
        
        
           25
        
         stu SS[
        
          10001
        
        
          ];


        
        
           26
        
        
           27
        
        
           28
        
        
           29
        
        
           30
        
        
           31
        
        
           32
        
        
           33
        
        
          bool
        
        
           cmp1(stu a,stu b)


        
        
           34
        
        
           35
        
        
          {


        
        
           36
        
        
           37
        
        
          return
        
         a.A>
        
          b.A;


        
        
           38
        
        
           39
        
        
          }


        
        
           40
        
        
           41
        
        
           42
        
        
           43
        
        
           44
        
        
           45
        
        
          bool
        
        
           cmp2(stu a,stu b)


        
        
           46
        
        
           47
        
        
          {


        
        
           48
        
        
           49
        
        
          return
        
         a.C>
        
          b.C;


        
        
           50
        
        
           51
        
        
          }


        
        
           52
        
        
           53
        
        
           54
        
        
           55
        
        
          bool
        
        
           cmp3(stu a,stu b)


        
        
           56
        
        
           57
        
        
          {


        
        
           58
        
        
           59
        
        
          return
        
         a.M>
        
          b.M;


        
        
           60
        
        
           61
        
        
          }


        
        
           62
        
        
           63
        
        
           64
        
        
           65
        
        
           66
        
        
           67
        
        
          bool
        
        
           cmp4(stu a,stu b)


        
        
           68
        
        
           69
        
        
          {


        
        
           70
        
        
           71
        
        
          return
        
         a.E>
        
          b.E;


        
        
           72
        
        
           73
        
        
          }


        
        
           74
        
        
           75
        
        
           76
        
        
           77
        
        
          int
        
        
           main()


        
        
           78
        
        
           79
        
        
          {


        
        
           80
        
        
           81
        
        
           82
        
        
           83
        
        
          int
        
        
           n;


        
        
           84
        
        
           85
        
        
          while
        
        (cin>>
        
          n)


        
        
           86
        
        
           87
        
        
                {


        
        
           88
        
        
           89
        
        
          int
        
        
           m,i;


        
        
           90
        
        
           91
        
                  cin>>
        
          m;


        
        
           92
        
        
           93
        
        
           94
        
        
           95
        
        
          for
        
        (i=
        
          0
        
        ;i<n;i++
        
          )


        
        
           96
        
        
           97
        
        
                   {


        
        
           98
        
        
           99
        
        
          100
        
        
          101
        
                        cin>>SS[i].ID>>SS[i].C>>SS[i].M>>
        
          SS[i].E;


        
        
          102
        
        
          103
        
        
                   }


        
        
          104
        
        
          105
        
        
          106
        
        
          107
        
        
          108
        
        
          109
        
        
          for
        
        (i=
        
          0
        
        ;i<n;i++
        
          )


        
        
          110
        
        
          111
        
        
                   {


        
        
          112
        
        
          113
        
                         SS[i].A=(SS[i].C+SS[i].M+SS[i].E)/
        
          3
        
        
          ;


        
        
          114
        
        
          115
        
                             SS[i].ra=
        
          1
        
        
          ;


        
        
          116
        
        
          117
        
                             SS[i].rc=
        
          1
        
        
          ;


        
        
          118
        
        
          119
        
                             SS[i].rm=
        
          1
        
        
          ;


        
        
          120
        
        
          121
        
                             SS[i].re=
        
          1
        
        
          ;


        
        
          122
        
        
          123
        
        
                   }


        
        
          124
        
        
          125
        
        
          126
        
        
          127
        
        
          128
        
        
          129
        
        
          130
        
        
          131
        
                sort(SS,SS+
        
          n,cmp1);


        
        
          132
        
        
          133
        
        
          int
        
         count=
        
          1
        
        
          ;


        
        
          134
        
        
          135
        
        
          for
        
        (i=
        
          1
        
        ;i<n;i++
        
          )


        
        
          136
        
        
          137
        
        
                      {


        
        
          138
        
        
          139
        
        
          if
        
        (SS[i].A==SS[i-
        
          1
        
        
          ].A)


        
        
          140
        
        
          141
        
        
                            {


        
        
          142
        
        
          143
        
                               SS[i].ra=SS[i-
        
          1
        
        
          ].ra;


        
        
          144
        
        
          145
        
                                       count++
        
          ;


        
        
          146
        
        
          147
        
        
                            }


        
        
          148
        
        
          149
        
        
          else
        
        
          150
        
        
          151
        
        
                              {


        
        
          152
        
        
          153
        
                                SS[i].ra=SS[i-
        
          1
        
        ].ra+
        
          count;


        
        
          154
        
        
          155
        
                                 count=
        
          1
        
        
          ;


        
        
          156
        
        
          157
        
        
                              }


        
        
          158
        
        
          159
        
        
                   }


        
        
          160
        
        
          161
        
        
          162
        
        
          163
        
        
          164
        
        
          165
        
                     sort(SS,SS+
        
          n,cmp2);


        
        
          166
        
        
          167
        
        
          168
        
        
          169
        
                   count=
        
          1
        
        
          ;


        
        
          170
        
        
          171
        
        
          for
        
        (i=
        
          1
        
        ;i<n;i++
        
          )


        
        
          172
        
        
          173
        
        
                   {


        
        
          174
        
        
          175
        
        
          if
        
        (SS[i].C==SS[i-
        
          1
        
        
          ].C)


        
        
          176
        
        
          177
        
        
                            {


        
        
          178
        
        
          179
        
                               SS[i].rc=SS[i-
        
          1
        
        
          ].rc;


        
        
          180
        
        
          181
        
                                       count++
        
          ;


        
        
          182
        
        
          183
        
        
                            }


        
        
          184
        
        
          185
        
        
          else
        
        
          186
        
        
          187
        
        
                              {


        
        
          188
        
        
          189
        
                                SS[i].rc=SS[i-
        
          1
        
        ].rc+
        
          count;


        
        
          190
        
        
          191
        
                                 count=
        
          1
        
        
          ;


        
        
          192
        
        
          193
        
        
                              }


        
        
          194
        
        
          195
        
        
                   }


        
        
          196
        
        
          197
        
        
          198
        
        
          199
        
        
          200
        
        
          201
        
                     sort(SS,SS+
        
          n,cmp3);


        
        
          202
        
        
          203
        
                  count=
        
          1
        
        
          ;


        
        
          204
        
        
          205
        
        
          for
        
        (i=
        
          1
        
        ;i<n;i++
        
          )


        
        
          206
        
        
          207
        
        
                   {


        
        
          208
        
        
          209
        
        
          if
        
        (SS[i].M==SS[i-
        
          1
        
        
          ].M)


        
        
          210
        
        
          211
        
        
                            {


        
        
          212
        
        
          213
        
                               SS[i].rm=SS[i-
        
          1
        
        
          ].rm;


        
        
          214
        
        
          215
        
                                       count++
        
          ;


        
        
          216
        
        
          217
        
        
                            }


        
        
          218
        
        
          219
        
        
          else
        
        
          220
        
        
          221
        
        
                              {


        
        
          222
        
        
          223
        
                                SS[i].rm=SS[i-
        
          1
        
        ].rm+
        
          count;


        
        
          224
        
        
          225
        
                                 count=
        
          1
        
        
          ;


        
        
          226
        
        
          227
        
        
                              }


        
        
          228
        
        
          229
        
        
                   }


        
        
          230
        
        
          231
        
        
          232
        
        
          233
        
        
          234
        
        
          235
        
                     sort(SS,SS+
        
          n,cmp4);


        
        
          236
        
        
          237
        
                  count=
        
          1
        
        
          ;


        
        
          238
        
        
          239
        
        
          for
        
        (i=
        
          1
        
        ;i<n;i++
        
          )


        
        
          240
        
        
          241
        
        
                   {


        
        
          242
        
        
          243
        
        
          if
        
        (SS[i].E==SS[i-
        
          1
        
        
          ].E)


        
        
          244
        
        
          245
        
        
                            {


        
        
          246
        
        
          247
        
                               SS[i].re=SS[i-
        
          1
        
        
          ].re;


        
        
          248
        
        
          249
        
                                       count++
        
          ;


        
        
          250
        
        
          251
        
        
                            }


        
        
          252
        
        
          253
        
        
          else
        
        
          254
        
        
          255
        
        
                              {


        
        
          256
        
        
          257
        
                                SS[i].re=SS[i-
        
          1
        
        ].re+
        
          count;


        
        
          258
        
        
          259
        
                                 count=
        
          1
        
        
          ;


        
        
          260
        
        
          261
        
        
                              }


        
        
          262
        
        
          263
        
        
                   }


        
        
          264
        
        
          265
        
        
          266
        
        
          267
        
        
          268
        
        
          269
        
        
          for
        
        (i=
        
          0
        
        ;i<m;i++
        
          )


        
        
          270
        
        
          271
        
        
                   {


        
        
          272
        
        
          273
        
        
          string
        
         goal;
        
          int
        
        
           j;


        
        
          274
        
        
          275
        
                       cin>>
        
          goal;


        
        
          276
        
        
          277
        
        
          for
        
        (j=
        
          0
        
        ;j<n;j++
        
          )


        
        
          278
        
        
          279
        
        
          if
        
        (SS[j].ID==goal) 
        
          break
        
        
          ;


        
        
          280
        
        
          281
        
        
          282
        
        
          283
        
        
          if
        
        (j==n) cout<<
        
          "
        
        
          N/A
        
        
          "
        
        <<
        
          endl;


        
        
          284
        
        
          285
        
        
          else
        
        
          {           


        
        
          286
        
        
          287
        
        
          char
        
         high=
        
          '
        
        
          E
        
        
          '
        
        
          ;


        
        
          288
        
        
          289
        
        
          int
        
         temp=
        
          SS[j].re;


        
        
          290
        
        
          291
        
        
          if
        
        (temp>=
        
          SS[j].rm)


        
        
          292
        
        
          293
        
        
                            {


        
        
          294
        
        
          295
        
                              high=
        
          '
        
        
          M
        
        
          '
        
        
          ;


        
        
          296
        
        
          297
        
                              temp=
        
          SS[j].rm;


        
        
          298
        
        
          299
        
        
                            }


        
        
          300
        
        
          301
        
        
          if
        
        (temp>=
        
          SS[j].rc)


        
        
          302
        
        
          303
        
        
                            {


        
        
          304
        
        
          305
        
                              high=
        
          '
        
        
          C
        
        
          '
        
        
          ;


        
        
          306
        
        
          307
        
                              temp=
        
          SS[j].rc;


        
        
          308
        
        
          309
        
        
                            }


        
        
          310
        
        
          311
        
        
          if
        
        (temp>=
        
          SS[j].ra)


        
        
          312
        
        
          313
        
        
                            {


        
        
          314
        
        
          315
        
                              high=
        
          '
        
        
          A
        
        
          '
        
        
          ;


        
        
          316
        
        
          317
        
                              temp=
        
          SS[j].ra;


        
        
          318
        
        
          319
        
        
                            }


        
        
          320
        
        
          321
        
        
          322
        
        
          323
        
                           cout<<temp<<
        
          "
        
        
          "
        
        <<high<<
        
          endl;


        
        
          324
        
        
          325
        
        
                      }


        
        
          326
        
        
          327
        
        
                   }


        
        
          328
        
        
          329
        
        
                }


        
        
          330
        
        
          331
        
        
          return
        
        
          0
        
        
          ;


        
        
          332
        
        
          333
        
        
          }


        
        
          334
        
        
          335
        
      
View Code

?

The Best Rank (25)(排名算法)


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 精品视频在线播放 | 岛国大片免费在线观看 | 亚洲免费色视频 | 久久97精品久久久久久久看片 | 中文字幕av在线 | 超清乱人伦中文视频在线 | 在线视频 亚洲 | 四虎影在线永久免费观看 | 欧美做爱毛片 | 毛片不卡一区二区三区 | 欧美三级做爰在线 | 黑人特黄aa毛片 | 四虎永久免费地址在线网站 | 白蛇缘起3免费观看 | 天天做夜夜操 | 亚洲第一成年网 | 国产农村妇女毛片精品久久久 | 综合激情五月婷婷 | 91精品成人福利在线播放 | 四虎精品在线 | 中文字幕精品在线观看 | 五月婷婷精品 | 日本亚欧乱色视频在线网站 | 亚洲最大在线观看 | 久久天堂成人影院 | 国产精品久久久久9999高清 | 爱爱小视频免费 | 久久精品一区二区影院 | 99精品国产费观看视频 | 深夜成人性视频免费看 | 99色视频| 久久精品国产国产精品四凭 | a级在线观看视频 | 国产成人一区二区三区在线播放 | 国模极品一区二区三区 | 国产成人精视频在线观看免费 | 亚洲乱码中文字幕久久 | 亚洲a视频在线 | 精品久久久久久中文字幕 | 狠狠色狠狠色综合久久第一次 | 久久精品视频亚洲 |