Advertisement
Korotkodul

21-22_N4_v2

Mar 22nd, 2023 (edited)
606
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.46 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4. #include <queue>
  5. #include <algorithm>
  6. #include <string>
  7. #include <stack>
  8. #include <set>
  9. #include <map>
  10. #define pii pair <int, int>
  11. #define pb(x) push_back(x)
  12. using namespace std;
  13. using ll = long long;
  14. using ld = long double;
  15. using db = double;
  16. void cv(vector <int> &v) {
  17.     for (auto x : v) cout << x << ' ';
  18.     cout << "\n";
  19. }
  20.  
  21. void cvl(vector <ll> &v) {
  22.     for (auto x : v) cout << x << ' ';
  23.     cout << "\n";
  24. }
  25.  
  26.  
  27. void cvv(vector <vector <int> > &v) {
  28.     for (auto x : v) cv(x);
  29.     cout << "\n";
  30. }
  31.  
  32. void cvb(vector <bool> v) {
  33.     for (bool x : v) cout << x << ' ';
  34.     cout << "\n";
  35. }
  36.  
  37. void cvs(vector <string>  v) {
  38.     for (auto a : v) {
  39.         cout << a << "\n";
  40.     }
  41. }
  42.  
  43. void cvp(vector <pii> a) {
  44.     for (auto p : a) {
  45.         cout << p.first << ' ' << p.second << "\n";
  46.     }
  47.     cout << "\n";
  48. }
  49.  
  50.  
  51. struct obj {
  52.     int id;
  53.     string name;
  54.     vector <int> link;//ведь изначально объявляется в структуре пустым или это не так работает?
  55.     void get() {
  56.         cout << id << ' ' <<  name  << "\n";
  57.         cv(link);
  58.         cout << "\n\n";
  59.     }
  60. };
  61.  
  62. void add(map <int, obj> &mp, obj el) {
  63.     mp[el.id] = el;
  64. }
  65.  
  66. int main() {
  67.     ios::sync_with_stdio(0);
  68.     cin.tie(0);
  69.     cout.tie(0);
  70.    
  71.     bool sh = 1;
  72.    
  73.     map <int, obj> school, clas, student;
  74.     int S, C, P;
  75.     cin >> S;
  76.     for (int i = 0; i < S; ++i) {
  77.         obj school_now;
  78.         cin >> school_now.id >> school_now.name;
  79.         add(school, school_now);
  80.     }
  81.  
  82.     cin >> C;
  83.     for (int i = 0; i < C; ++i) {
  84.         obj clas_now;
  85.         int school_id;
  86.         cin >> clas_now.id >> school_id >> clas_now.name;
  87.         add(clas, clas_now);
  88.         school[school_id].link.pb(clas_now.id);
  89.     }
  90.  
  91.     cin >> P;
  92.     for (int i = 0; i < P; ++i) {
  93.         obj student_now;
  94.         int clas_id;
  95.         cin >> student_now.id >> clas_id >> student_now.name;
  96.         add(student, student_now);
  97.         clas[clas_id].link.pb(student_now.id);
  98.     }
  99.    
  100.  
  101.     //сортим все id
  102.     for (pair <int, obj> p: school) {
  103.         obj el = p.second;
  104.         sort(el.link.begin(), el.link.end());
  105.         school[el.id] = el;
  106.     }
  107.     for (pair <int, obj> p: clas) {
  108.         obj el = p.second;
  109.         sort(el.link.begin(), el.link.end());
  110.         clas[el.id] = el;
  111.     }
  112.     for (pair <int, obj> p: student) {
  113.         obj el = p.second;
  114.         sort(el.link.begin(), el.link.end());
  115.         student[el.id] = el;
  116.     }
  117.  
  118.     //выводим
  119.     for (auto pair_school: school) {//ведь в map-е значения отсорчены по ключам?
  120.         obj school_now = pair_school.second;
  121.         string s1 = to_string(school_now.id) + " " + school_now.name;
  122.         if (school_now.link.empty()) {
  123.             cout << s1 << "\n";
  124.             continue;
  125.         }
  126.         for (int clas_id: school_now.link) {
  127.             obj clas_now = clas[clas_id];
  128.             string s2 = s1 + to_string(clas_now.id) + " " + clas_now.name;
  129.             if (clas_now.link.empty()) {
  130.                 cout << s2 << "\n";
  131.                 continue;
  132.             }
  133.             for (int student_id: clas_now.link) {
  134.                 obj student_now = student[student_id];
  135.                 string s3 = s2 + to_string(student_now.id) + " " + student_now.name;
  136.                 cout << s3 << "\n";
  137.             }
  138.         }
  139.     }
  140. }
  141.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement