Advertisement
Dzham

slozhna

Nov 19th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.10 KB | None | 0 0
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <vector>
  4. #include <map>
  5. #include <string>
  6.  
  7. using std::cout;
  8. using std::cin;
  9. using std::string;
  10.  
  11. struct student {
  12. string name;
  13. string surname;
  14. int day;
  15. int month;
  16. int year;
  17. int score;
  18. int number;
  19. std::vector<string> university;
  20. };
  21.  
  22. bool compare_entry(const student & student1, const student & student2) {
  23. if (student1.score != student2.score) {
  24. return student1.score > student2.score;
  25. } else if (student1.year != student2.year) {
  26. return (student1.year < student2.year);
  27. } else if (student1.month != student2.month) {
  28. return (student1.month < student2.month);
  29. } else if (student1.day != student2.day) {
  30. return (student1.day < student2.day);
  31. } else if (student1.surname != student2.surname) {
  32. return (student1.surname < student2.surname);
  33. }
  34. return (student1.name < student2.name);
  35. }
  36.  
  37. bool compare_entry2(const string & string1, const string & string2) {
  38. return (string1 < string2);
  39. }
  40.  
  41. int main() {
  42. int N, M;
  43. string call, name1, name2, day, month, year, date, sco, number, univ;
  44. std::vector<student> students, result;
  45. std::vector<string> universities, k;
  46. std::map<string, int> places;
  47. std::map<string, std::vector<string>> results;
  48. cin >> N;
  49. for (int i = 0; i < N; i++) {
  50. cin >> univ;
  51. cin >> number;
  52. places[univ] = stoi(number);
  53. universities.push_back(univ);
  54. }
  55. cin >> M;
  56. for (int i = 0; i < M; i++) {
  57. student stud;
  58. cin >> name1;
  59. cin >> name2;
  60. cin >> day;
  61. cin >> month;
  62. cin >> year;
  63. cin >> sco;
  64. cin >> number;
  65. stud.name = name1;
  66. stud.surname = name2;
  67. stud.day = std::stoi(day);
  68. stud.month = std::stoi(month);
  69. stud.year = std::stoi(year);
  70. stud.score = std::stoi(sco);
  71. stud.number = std::stoi(number);
  72. for (int j = 0; j < stud.number; j++) {
  73. cin >> univ;
  74. stud.university.push_back(univ);
  75. }
  76. students.push_back(stud);
  77. }
  78. std::sort(students.begin(), students.end(), compare_entry2);
  79. for (int i = 0; i < N; i++) {
  80. std::vector<string> empty = {};
  81. results[universities[i]] = empty;
  82. }
  83. for (int i = 0; i < M; i++) {
  84. for (int j = 0; j < students[i].number; j++) {
  85. if (places.at(students[i].university[j]) > 0) {
  86. places.at(students[i].university[j]) -= 1;
  87. k = results[students[i].university[j]];
  88. k.push_back(students[i].name + ' ' + students[i].surname);
  89. results.at(students[i].university[j]) = k;
  90. j = students[i].number;
  91. }
  92. }
  93. }
  94. std::sort(universities.begin(), universities.end());
  95. int j = 0;
  96. for (int i = 0; i < N; i++) {
  97. cout << universities[i];
  98. for (j = 0; j < results.at(universities[i]).size(); j++) {
  99. cout << '\t' << results.at(universities[i])[j];
  100. }
  101. cout << '\n';
  102. }
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement