section3-3.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <algorithm>
  5. using namespace std;
  6. struct Grade {
  7. string Id;
  8. int Score;
  9. };
  10. bool compare(Grade a, Grade b) {
  11. if (a.Score > b.Score) {
  12. return true;
  13. } else if (a.Score < b.Score) {
  14. return false;
  15. }
  16. return a.Id < b.Id;
  17. }
  18. int main() {
  19. int N = 0, M = 0, G = 0;
  20. int *questions;
  21. while (cin >> N && N) {
  22. cin >> M >> G;
  23. questions = new int[M];
  24. vector<Grade> grade;
  25. // input question scoreIndex
  26. for (int i = 0; i < M; i++) {
  27. cin >> questions[i];
  28. }
  29. int answer;
  30. int total, scoreIndex;
  31. string id;
  32. for (int i = 0; i < N; i++) {
  33. answer = 0;
  34. total = 0, scoreIndex = 0;
  35. cin >> id;
  36. cin >> answer;
  37. for (int j = 0; j < answer; j++) {
  38. cin >> scoreIndex;
  39. total += questions[scoreIndex - 1];
  40. }
  41. if (total < G) {
  42. continue;
  43. }
  44. Grade tempGrade = {id, total};
  45. grade.push_back(tempGrade);
  46. }
  47. sort(grade.begin(), grade.end(), compare);
  48. cout << grade.size() << endl;
  49. for (int i = 0; i < (grade.size()); i++) {
  50. cout << grade.at(i).Id << " " << grade.at(i).Score << endl;
  51. }
  52. free(questions);
  53. grade.clear();
  54. }
  55. }