Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <vector>
- #include <queue>
- #include <algorithm>
- #include <string>
- #include <stack>
- #include <set>
- #include <map>
- #define pii pair <int, int>
- #define pb(x) push_back(x)
- using namespace std;
- using ll = long long;
- using ld = long double;
- using db = double;
- void cv(vector <int> &v) {
- for (auto x : v) cout << x << ' ';
- cout << "\n";
- }
- void cvl(vector <ll> &v) {
- for (auto x : v) cout << x << ' ';
- cout << "\n";
- }
- void cvv(vector <vector <int> > &v) {
- for (auto x : v) cv(x);
- cout << "\n";
- }
- void cvb(vector <bool> v) {
- for (bool x : v) cout << x << ' ';
- cout << "\n";
- }
- void cvs(vector <string> v) {
- for (auto a : v) {
- cout << a << "\n";
- }
- }
- void cvp(vector <pii> a) {
- for (auto p : a) {
- cout << p.first << ' ' << p.second << "\n";
- }
- cout << "\n";
- }
- struct obj {
- int id;
- string name;
- vector <int> link;//ведь изначально объявляется в структуре пустым или это не так работает?
- void get() {
- cout << id << ' ' << name << "\n";
- cv(link);
- cout << "\n\n";
- }
- };
- void add(map <int, obj> &mp, obj el) {
- mp[el.id] = el;
- }
- int main() {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- bool sh = 1;
- map <int, obj> school, clas, student;
- int S, C, P;
- cin >> S;
- for (int i = 0; i < S; ++i) {
- obj school_now;
- cin >> school_now.id >> school_now.name;
- add(school, school_now);
- }
- cin >> C;
- for (int i = 0; i < C; ++i) {
- obj clas_now;
- int school_id;
- cin >> clas_now.id >> school_id >> clas_now.name;
- add(clas, clas_now);
- school[school_id].link.pb(clas_now.id);
- }
- cin >> P;
- for (int i = 0; i < P; ++i) {
- obj student_now;
- int clas_id;
- cin >> student_now.id >> clas_id >> student_now.name;
- add(student, student_now);
- clas[clas_id].link.pb(student_now.id);
- }
- //сортим все id
- for (pair <int, obj> p: school) {
- obj el = p.second;
- sort(el.link.begin(), el.link.end());
- school[el.id] = el;
- }
- for (pair <int, obj> p: clas) {
- obj el = p.second;
- sort(el.link.begin(), el.link.end());
- clas[el.id] = el;
- }
- for (pair <int, obj> p: student) {
- obj el = p.second;
- sort(el.link.begin(), el.link.end());
- student[el.id] = el;
- }
- //выводим
- for (auto pair_school: school) {//ведь в map-е значения отсорчены по ключам?
- obj school_now = pair_school.second;
- string s1 = to_string(school_now.id) + " " + school_now.name;
- if (school_now.link.empty()) {
- cout << s1 << "\n";
- continue;
- }
- for (int clas_id: school_now.link) {
- obj clas_now = clas[clas_id];
- string s2 = s1 + to_string(clas_now.id) + " " + clas_now.name;
- if (clas_now.link.empty()) {
- cout << s2 << "\n";
- continue;
- }
- for (int student_id: clas_now.link) {
- obj student_now = student[student_id];
- string s3 = s2 + to_string(student_now.id) + " " + student_now.name;
- cout << s3 << "\n";
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement