HDU1177 "Accepted today?"

题目链接:http://acm.pku.edu.cn/JudgeOnline/problem?id=1177

  
  
  
  
  1. #include <iostream> 
  2. #include <algorithm> 
  3. #include <string> 
  4. using namespace std;  
  5.  
  6. const int MAX_SIZE = 150;  
  7.  
  8. struct score  
  9. {  
  10.     int problems;//解出的题数  
  11.     string time;//用时  
  12.     bool isTarget;//是否目标  
  13. };  
  14.  
  15. struct score scores[MAX_SIZE];  
  16. int N,G,S,C,M,P;  
  17.  
  18. bool compare(const score& s1, const score &s2)  
  19. {  
  20.     if (s1.problems > s2.problems)  
  21.     {  
  22.         return true;  
  23.     }  
  24.     else if (s1.problems < s2.problems)  
  25.     {  
  26.         return false;  
  27.     }  
  28.     else  
  29.     {//题数相同,比较用时  
  30.         if (s1.time.compare(s2.time) > 0)  
  31.         {  
  32.             return false;  
  33.         }  
  34.         else if (s1.time.compare(s2.time) < 0)  
  35.         {  
  36.             return true;  
  37.         }  
  38.     }  
  39. }  
  40.  
  41. int findTargetPos()  
  42. {//找到排序后的目标位置  
  43.     int pos = -1;  
  44.     for (int i = 0; i < N; ++i)  
  45.     {  
  46.         if (scores[i].isTarget == true)  
  47.         {  
  48.             pos = i;  
  49.             break;  
  50.         }  
  51.     }  
  52.     return pos + 1;  
  53. }  
  54.  
  55. int main()  
  56. {  
  57.     int i,pos;  
  58.     while (cin >> N >> G >> S >> C >> M )  
  59.     {  
  60.         if(N == 0 && G == 0 && S == 0 && C == 0 && M == 0)break;  
  61.         for (i = 0; i < N; ++i)  
  62.         {  
  63.             cin >> scores[i].problems >> scores[i].time;  
  64.             scores[i].isTarget = false;  
  65.             if (i == M - 1)  
  66.             {  
  67.                 scores[i].isTarget = true;  
  68.             }  
  69.         }  
  70.         sort(scores, scores + N, compare);  
  71.         pos = findTargetPos();  
  72.         if (pos <= G)  
  73.         {  
  74.             cout <<"Accepted today? I've got a golden medal :)" << endl;  
  75.         }  
  76.         else if (pos <= G + S)  
  77.         {  
  78.             cout <<"Accepted today? I've got a silver medal :)" << endl;  
  79.         }  
  80.         else if (pos <= G + S + C)  
  81.         {  
  82.             cout <<"Accepted today? I've got a copper medal :)" << endl;  
  83.         }  
  84.         else  
  85.         {  
  86.             cout << "Accepted today? I've got an honor mentioned :)" << endl;  
  87.         }  
  88.     }  
  89.     return 0;  
  90. }  
  91.  

 

你可能感兴趣的:(职场,ACM,休闲)