Advertisement
Korotkodul

21-22_N4_v3_for_check

Mar 23rd, 2023 (edited)
529
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.96 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. map <int, obj> school, clas, student;
  67.  
  68. void look(map <int, obj> mp) {
  69.     for (auto p: mp) {
  70.         int key = p.first;
  71.         obj el = p.second;
  72.         cout << "key = " << key << "\n";
  73.         cout << "el\n";
  74.         el.get();
  75.     }
  76.     cout << "END\n\n";
  77. }
  78.  
  79. int main() {
  80.     /*ios::sync_with_stdio(0);
  81.     cin.tie(0);
  82.     cout.tie(0);*/
  83.  
  84.     bool sh = 0;
  85.  
  86.  
  87.     int S, C, P;
  88.  
  89.     cin >> S;
  90.     for (int i = 0; i < S; ++i) {
  91.         obj school_now;
  92.         cin >> school_now.id >> school_now.name;
  93.         add(school, school_now);
  94.     }
  95.  
  96.     cin >> C;
  97.     for (int i = 0; i < C; ++i) {
  98.         obj clas_now;
  99.         int school_id;
  100.         cin >> clas_now.id >> school_id >> clas_now.name;
  101.         add(clas, clas_now);
  102.         school[school_id].link.pb(clas_now.id);
  103.     }
  104.  
  105.     cin >> P;
  106.     for (int i = 0; i < P; ++i) {
  107.         obj student_now;
  108.         int clas_id;
  109.         string s1, s2;
  110.         cin >> student_now.id >> clas_id >> s1 >> s2;
  111.         student_now.name = s1 + " " + s2;
  112.         add(student, student_now);
  113.         clas[clas_id].link.pb(student_now.id);
  114.     }
  115.  
  116.  
  117.  
  118.     //сортим все id
  119.     for (pair <int, obj> p: school) {
  120.         obj el = p.second;
  121.         sort(el.link.begin(), el.link.end());
  122.         school[el.id] = el;
  123.     }
  124.     for (pair <int, obj> p: clas) {
  125.         obj el = p.second;
  126.         sort(el.link.begin(), el.link.end());
  127.         clas[el.id] = el;
  128.     }
  129.     for (pair <int, obj> p: student) {
  130.         obj el = p.second;
  131.         sort(el.link.begin(), el.link.end());
  132.         student[el.id] = el;
  133.     }
  134.  
  135.     if (sh) {
  136.         cout << "SCHOOL\n";
  137.         look(school);
  138.         cout << "CLAS\n";
  139.         look(clas);
  140.         cout << "STUDENT\n";
  141.         look(student);
  142.     }
  143.  
  144.  
  145.  
  146.  
  147.  
  148.     //выводим
  149.  
  150.  
  151.     cout << "ANSWER\n";
  152.     for (auto pair_school: school) {//ведь в map-е значения отсорчены по ключам?
  153.         obj school_now = pair_school.second;
  154.         string s1 = to_string(school_now.id) + " " + school_now.name;
  155.         if (school_now.link.empty()) {
  156.             cout << s1 << "\n";
  157.             continue;
  158.         }
  159.         for (int clas_id: school_now.link) {
  160.             obj clas_now = clas[clas_id];
  161.             string s2 = s1 + " " + to_string(clas_now.id) + " " + clas_now.name;
  162.             if (clas_now.link.empty()) {
  163.                 cout << s2 << "\n";
  164.                 continue;
  165.             }
  166.             for (int student_id: clas_now.link) {
  167.                 obj student_now = student[student_id];
  168.                 string s3 = s2 + " " + to_string(student_now.id) + " " + student_now.name;
  169.                 cout << s3 << "\n";
  170.             }
  171.         }
  172.     }
  173.  
  174. }
  175.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement