• PAT1012


    题目大坑,注意排名规则,题目没有说清楚,90 85 85 80 的排名不是1 2 3 4  而是1 2 2 4  注意并列!

      1 #include<iostream>
      2 #include<vector>
      3 #include<string>
      4 #include<map>
      5 #include<algorithm>
      6 #include<iterator>
      7 using namespace std;
      8 
      9 struct VNode
     10 {
     11     string id;
     12     double grade;
     13 };
     14 
     15 double round(double num)
     16 {
     17     int n =(int)num+1;
     18     if(num + 0.5 >= n)
     19         return (double)n;
     20     else
     21         return (double)n-1;
     22 }
     23 
     24 struct MNode
     25 {
     26     int c_rank;
     27     int m_rank;
     28     int e_rank;
     29     int a_rank;
     30 };
     31 
     32 bool comp(VNode n1, VNode n2)
     33 {
     34     if(n1.grade > n2.grade)
     35         return true;
     36     else
     37         return false;
     38 }
     39 
     40 int best (MNode p, char &ch)
     41 {
     42     int q[4]={p.a_rank, p.c_rank, p.m_rank, p.e_rank};
     43     int rank = 10000, index;
     44     for(int i=0; i<4; ++i)
     45         if(q[i] < rank)
     46         {
     47             rank = q[i];
     48             index = i;
     49         }
     50     switch (index)
     51     {
     52         case 0: {ch = 'A';break;}
     53         case 1: {ch = 'C';break;}
     54         case 2: {ch = 'M';break;}
     55         case 3: {ch = 'E';break;}
     56     }
     57     return rank;
     58 }
     59 
     60 int main()
     61 {
     62     int enroll, check;
     63     while(cin>>enroll>>check)
     64     {
     65         vector<VNode> C, M, E, A;
     66         vector<string> checklist(check);
     67         for(int i=0; i<enroll; ++i)
     68         {
     69             string id; double c, m ,e ,a;
     70             cin>>id>>c>>m>>e;
     71             a = round((c+m+e)/3);
     72             VNode cn={id,c}; C.push_back(cn);
     73             VNode mn={id,m}; M.push_back(mn);
     74             VNode en={id,e}; E.push_back(en);
     75             VNode an={id,a}; A.push_back(an);
     76         }
     77         for(int i=0; i<check; ++i)
     78             cin>>checklist[i];
     79 
     80         stable_sort(C.begin(), C.end(), comp);
     81         stable_sort(M.begin(), M.end(), comp);
     82         stable_sort(E.begin(), E.end(), comp);
     83         stable_sort(A.begin(), A.end(), comp);
     84 
     85         map<string, MNode> ranklist;
     86 
     87         for(int i=0; i<C.size(); ++i)
     88             if(i != 0)
     89             {
     90                 if(C[i].grade == C[i-1].grade)
     91                     ranklist[C[i].id].c_rank = ranklist[C[i-1].id].c_rank;
     92                 else
     93                     ranklist[C[i].id].c_rank = i+1;
     94             }
     95             else
     96                 ranklist[C[i].id].c_rank = i+1;
     97         /*处理并列排名,天坑啊,题目压根没说*/
     98         for(int i=0; i<M.size(); ++i)
     99             if(i != 0)
    100             {
    101                 if(M[i].grade == M[i-1].grade)
    102                     ranklist[M[i].id].m_rank = ranklist[M[i-1].id].m_rank;
    103                 else
    104                     ranklist[M[i].id].m_rank = i+1;
    105             }
    106             else
    107                 ranklist[M[i].id].m_rank = i+1;
    108 
    109         for(int i=0; i<E.size(); ++i)
    110             if(i != 0)
    111             {
    112                 if(E[i].grade == E[i-1].grade)
    113                     ranklist[E[i].id].e_rank = ranklist[E[i-1].id].e_rank;
    114                 else
    115                     ranklist[E[i].id].e_rank = i+1;
    116             }
    117             else
    118                 ranklist[E[i].id].e_rank = i+1;
    119 
    120         for(int i=0; i<A.size(); ++i)
    121             if(i != 0)
    122             {
    123                 if(A[i].grade == A[i-1].grade)
    124                     ranklist[A[i].id].a_rank = ranklist[A[i-1].id].a_rank;
    125                 else
    126                     ranklist[A[i].id].a_rank = i+1;
    127             }
    128             else
    129                 ranklist[A[i].id].a_rank = i+1;
    130 
    131         for(int i=0; i < checklist.size(); ++i)
    132         {
    133             map<string, MNode>::iterator iter = ranklist.find(checklist[i]);
    134             if( iter == ranklist.end())
    135                 cout<<"N/A"<<endl;
    136             else
    137             {
    138                 char ch;
    139                 int b = best(iter->second,ch);
    140                 cout<<b<<" "<<ch<<endl;
    141             }
    142         }
    143     }
    144     return 0;
    145 }
  • 相关阅读:
    HDU6168 Numbers
    HDU6170 Two strings
    UVA11426 GCD
    hihocoder1560 H国的身份证号码II
    HDU6156 Palindrome Function
    UVA10917 Walk Through the Forest
    UVA11374 Airport Express
    hihocoder1323 回文字符串
    hihocoder1543 SCI表示法
    CodeForces501C Misha and Forest
  • 原文地址:https://www.cnblogs.com/bochen-sam/p/3349561.html
Copyright © 2020-2023  润新知