2014年8月21日 星期四

b021 "指考分發" (skipper)


  1. /**********************************************************************************/  
  2. /*  Problem: b021 "指考分發" from 排序-複合欄位                                             */  
  3. /*  Language: C++                                                                 */  
  4. /*  Result: AC (4ms, 200KB) on ZeroJudge                                          */  
  5. /*  Author: skipper at 2014-08-22 10:30:20                                        */  
  6. /**********************************************************************************/  
  7.   
  8. #include <iostream>  
  9. #include <algorithm>  
  10. #include <numeric>  
  11. using namespace std;  
  12. struct Score {  
  13.     int no,subj[5],total;  
  14. };  
  15. bool compare (Score a,Score b) {   
  16.     if (a.total>b.total) return true;      
  17.     if (a.total==b.total) return a.subj[2]>=b.subj[2];  
  18.     return false;   
  19. }  
  20.   
  21. int main ()  
  22. {  
  23.     int N; cin >> N;  
  24.     Score *s;  
  25.     s= new Score[N];  
  26.     for (int i=0;i<N;i++){  
  27.         cin >> s[i].no; s[i].total = 0;  
  28.         for (int j=0;j<5;j++) { cin >> s[i].subj[j];}  
  29.         s[i].total=accumulate(s[i].subj,s[i].subj+5,0);  
  30.     }  
  31.       
  32.     sort(s,s+N,compare);  
  33.     for (int i=0;i<N;i++){  
  34.         cout << s[i].no << endl;  
  35.     }  
  36. }  

沒有留言:

張貼留言