Advertisement
Guest User

Untitled

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