题目1324:The Best Rank
2013-04-29 15:09
197 查看
#include<iostream> #include<algorithm> #include<cstring> using namespace std; struct grade{ char stuID[7]; int cScore; int mScore; int eScore; double aScore; int rank; int temprank; char course; }; grade g[2000]; bool cmpBycSore(grade a,grade b){ return a.cScore > b.cScore; } bool cmpBymSore(grade a,grade b){ return a.mScore > b.mScore; } bool cmpByeSore(grade a,grade b){ return a.eScore > b.eScore; } bool cmpByaSore(grade a,grade b){ return a.aScore > b.aScore; } int main(){ int m,n; while(cin >> n >> m){ for(int i = 0 ; i < n ; i++){ cin >> g[i].stuID >> g[i].cScore >> g[i].mScore >> g[i].eScore; g[i].aScore = (g[i].cScore + g[i].mScore + g[i].eScore)/3; } sort(g,g + n,cmpByaSore); g[0].rank = 1; g[0].course = 'A'; for(int i = 1 ; i < n ; i++){ if(g[i].aScore == g[i-1].aScore) g[i].rank = g[i-1].rank; else g[i].rank = i + 1; g[i].course = 'A'; } sort(g,g + n,cmpBycSore); g[0].temprank = 1; for(int i = 1 ; i < n ; i++){ if(g[i].cScore == g[i-1].cScore) g[i].temprank = g[i-1].temprank; else g[i].temprank = i + 1; } for(int i = 0 ; i < n ; i++){ if(g[i].temprank < g[i].rank){ g[i].rank = g[i].temprank; g[i].course = 'C'; } } sort(g,g + n,cmpBymSore); g[0].temprank = 1; for(int i = 1 ; i < n ; i++){ if(g[i].mScore == g[i-1].mScore) g[i].temprank = g[i-1].temprank; else g[i].temprank = i + 1; } for(int i = 0 ; i < n ; i++){ if(g[i].temprank < g[i].rank){ g[i].rank = g[i].temprank; g[i].course = 'M'; } } sort(g,g + n,cmpByeSore); g[0].temprank = 1; for(int i = 1 ; i < n ; i++){ if(g[i].eScore == g[i-1].eScore) g[i].temprank = g[i-1].temprank; else g[i].temprank = i + 1; } for(int i = 0 ; i < n ; i++){ if(g[i].temprank < g[i].rank){ g[i].rank = g[i].temprank; g[i].course = 'E'; } } char query[7]; int i,j; for(i = 0;i < m;i++){ cin >> query; for(j = 0;j < n;j++) if(!strcmp(query,g[j].stuID)) break; if(j < n) cout << g[j].rank << " " << g[j].course << endl; else cout << "N/A" << endl; } } return 1; }
相关文章推荐
- 九度题目1324:The Best Rank
- 九度OJ 1324:The Best Rank(最优排名) (排序)
- 九度OJ 1324:The Best Rank(最优排名) (排序)
- [Jobdu] 1324: The Best Rank & 1007: 奥运排序问题 & 1009: 二叉搜索树
- 1012. The Best Rank (25)
- 1012. The Best Rank (25)
- PAT 1012. The Best Rank (25)
- PAT - 甲级 - 1012. The Best Rank (25)(排序)
- PAT甲级.1012. The Best Rank (25)
- [PAT (Advanced Level) ]1012. The Best Rank 解题文档
- Pat(Advanced Level)Practice--1012(The Best Rank)
- PAT甲级1012. The Best Rank (25)
- 1012. The Best Rank (25)
- 1012.The Best Rank
- PAT 1012. The Best Rank (25)
- 1012. The Best Rank (25)
- PAT 甲级 1012. The Best Rank (25)
- pat甲级1012. The Best Rank (25)
- pat1012 The Best Rank
- PAT1012:The Best Rank