WHCSRL 技术网

PAT甲级 1075(C++)_aoi

注意这句话:For those who has never submitted any solution that can pass the compiler, or has never submitted any solution, they must NOT be shown on the ranklist.

意思是   提交都没通过编译   和   没提交任何题目   的人不出现在排名表中,因此不能仅通过总分是否为0来判断(可能有人通过编译了但答案一个都不正确,总分为0

  1. #include<iostream>
  2. #include<vector>
  3. #include<algorithm>
  4. using namespace std;
  5. struct person {
  6. int id;
  7. int rank;
  8. int score;
  9. int perfect;
  10. int part[5];
  11. bool show;
  12. };
  13. vector<person>info;
  14. int full[5];
  15. bool compare(person p1, person p2) {
  16. if (p1.score != p2.score) return p1.score > p2.score;
  17. if (p1.perfect != p2.perfect) return p1.perfect > p2.perfect;
  18. if (p1.id != p2.id) return p1.id < p2.id;
  19. }
  20. int main() {
  21. int N, K, M;
  22. cin >> N >> K >> M;
  23. info.resize(N);
  24. for (int i = 0; i < N; i++) {
  25. info[i].id = i + 1;
  26. info[i].score = info[i].perfect = 0;
  27. fill(info[i].part, info[i].part + K, -1);
  28. info[i].show = 0;
  29. }
  30. for (int i = 0; i < K; i++)
  31. cin >> full[i];
  32. for (int i = 1; i <= M; i++) {
  33. int d, p, s;
  34. scanf("%%05d %%d %%d", &d, &p, &s);
  35. if (s < info[d - 1].part[p - 1]) continue;
  36. info[d - 1].part[p - 1] = (s==-1)?0:s;
  37. if (info[d - 1].show == 0 && s != -1) info[d - 1].show = 1;
  38. }
  39. for (int i = 0; i < N; i++) {
  40. for (int j = 0; j < K; j++) {
  41. info[i].score += (info[i].part[j]==-1)?0:info[i].part[j];
  42. if (info[i].part[j] == full[j])
  43. info[i].perfect++;
  44. }
  45. }
  46. sort(info.begin(), info.end(), compare);
  47. for (int i = 0; i < N; i++) {
  48. if (info[i].show==0) continue;
  49. if (i == 0) info[i].rank = 1;
  50. else if (info[i].score == info[i - 1].score)
  51. info[i].rank = info[i - 1].rank;
  52. else info[i].rank = i + 1;
  53. printf("%%d %%05d %%d ", info[i].rank, info[i].id, info[i].score);
  54. for (int j = 0; j < K; j++) {
  55. if (info[i].part[j] == -1) cout << "-";
  56. else cout << info[i].part[j];
  57. if (j != K - 1) cout << " ";
  58. else cout << endl;
  59. }
  60. }
  61. return 0;
  62. }

推荐阅读