fork download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. class EVENT {
  7. private:
  8. string date;
  9. string name;
  10. public:
  11. EVENT(string da, string na) : date(da), name(na) { }
  12. string GetDate() { return date; }
  13. void Info()
  14. {
  15. cout << "date: " << date << endl;
  16. cout << "name: " << name << endl;
  17. }
  18. };
  19.  
  20. class PROBLEM {
  21. private:
  22. string name;
  23. int points;
  24. public:
  25. PROBLEM(string n="", int p=0) : name(n), points(p) { }
  26. string GetName() { return name; }
  27. int GetPoints() { return points; }
  28. void Info() { cout << name << " " << points << endl; }
  29. };
  30.  
  31. class PROBLEMS {
  32. private:
  33. int number; // actual number of problems
  34. PROBLEM tasks[100]; // max number
  35. public:
  36. PROBLEMS(int n) : number(n) { }
  37. void AddProblem(int i, PROBLEM& p) { tasks[i] = p; }
  38. void Info() { for(int i=0;i<number;i++) tasks[i].Info(); }
  39. void SortedInfo();
  40. };
  41.  
  42. class EXAM : public EVENT, public PROBLEMS {
  43. public:
  44. EXAM(EVENT e, PROBLEMS p) : EVENT(e), PROBLEMS(p) {}
  45. void Info()
  46. {
  47. EVENT(*this).Info();
  48. PROBLEMS(*this).Info();
  49. }
  50. void SortedInfo();
  51. };
  52.  
  53.  
  54. void SortByDate(EXAM**, int);
  55.  
  56. int main()
  57. {
  58. string date, name;
  59. int num;
  60. int ps;
  61. EXAM* list[100]; // max. number of exams
  62.  
  63. cin >> num;
  64.  
  65. for(int i=0; i<num; i++)
  66. {
  67. cin >> date >> name >> ps;
  68. EXAM* exam = new EXAM(EVENT(date,name),PROBLEMS(ps));
  69. list[i] = exam;
  70.  
  71. for(int j=0; j<ps; j++)
  72. {
  73. string name;
  74. int pts;
  75. cin >> name >> pts;
  76. PROBLEM p(name,pts);
  77. exam->AddProblem(j, p);
  78. }
  79. }
  80.  
  81. SortByDate(list,num);
  82.  
  83. for(int i=0; i<num; i++) { list[i]->SortedInfo(); if (i<num-1) cout << "---" << endl; }
  84.  
  85. return 0;
  86. }
  87.  
  88. // begin: part 1, You are allowed to change the code ONLY between the brackets {} below in both methods
  89. void SortByDate(EXAM** list, int n)
  90. {
  91. for(int i = 0; i < n - 1; i++)
  92. {
  93. for(int j = 0; j < n - i - 1; j++)
  94. {
  95. if(list[j]->GetDate() > list[j + 1]->GetDate())
  96. swap(list[j], list[j + 1]);
  97. }
  98. }
  99. }
  100.  
  101. void EXAM::SortedInfo()
  102. {
  103. PROBLEMS::SortedInfo();
  104. Info();
  105. }
  106.  
  107. void PROBLEMS::SortedInfo()
  108. {
  109. for(int i = 0; i < number - 1; i++)
  110. {
  111. for(int j = 0; j < number - i - 1; j++)
  112. {
  113. if(tasks[j].GetPoints() == tasks[j + 1].GetPoints())
  114. {
  115. if(tasks[j].GetName() > tasks[j + 1].GetName())
  116. swap(tasks[j], tasks[j + 1]);
  117. }
  118. if(tasks[j].GetPoints() < tasks[j + 1].GetPoints())
  119. swap(tasks[j], tasks[j + 1]);
  120. }
  121. }
  122. }
  123. // end: part 1
Success #stdin #stdout 0.01s 4868KB
stdin
2
2021-01-18 final-exam-1 5
Problem1 5
Problem2 5
Problem3 15
Problem4 5
Problem5 15
2021-01-10 final-exam-2 3
Problem1 5
Problem2 5
Problem3 15
stdout
date: 2021-01-10
name: final-exam-2
Problem3 15
Problem1 5
Problem2 5
---
date: 2021-01-18
name: final-exam-1
Problem3 15
Problem5 15
Problem1 5
Problem2 5
Problem4 5