LegoSosiska

Ларцы

Dec 2nd, 2020
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.39 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <vector>
  4. #include <string>
  5. #include <utility>
  6.  
  7. struct box {
  8.     std::string name = "";
  9.     int num = 0;
  10.     bool obj = false;
  11. };
  12.  
  13. void Dive(std::vector<std::pair<box, std::vector<box>>>& a, int n, bool depth) {
  14.     for (int j = 0;; ++j) {
  15.         if (a[j].first.num == n) {
  16.             n = j;
  17.             break;
  18.         }
  19.     }
  20.     for (int i = 0; a[n].second[i].name != "" && i < 100; ++i) {
  21.         if (!a[n].second[i].obj) {
  22.             std::cout << a[n].second[i].name << " ";
  23.         }
  24.         else {
  25.             Dive(a, a[n].second[i].num, true);
  26.         }
  27.     }
  28.     if (!depth) {
  29.         std::cout << "\n";
  30.     }
  31.     return;
  32. }
  33.  
  34. int main() {
  35.     std::fstream str;
  36.     str.open("Input.txt");
  37.     if (!str.is_open()) {
  38.         std::cout << "FAILED TO OPEN FILE 1";
  39.         return 0;
  40.     }
  41.     std::vector<std::pair<box, std::vector<box>>> a(100);
  42.     for (int ind = 0; ind < 100; ++ind) {
  43.         a[ind].second.resize(100);
  44.     }
  45.     int i = 0;
  46.     while (!str.eof()) {
  47.         str >> a[i].first.name;
  48.         str >> a[i].first.num;
  49.         int j = -1;
  50.         bool f = false, k = false, gr = false;
  51.         for (char p; (p = str.get()) != '\n' && !str.eof();) {
  52.             if (p == ' ') {
  53.                 if (f && !gr) {
  54.                     a[i].second[j].obj = true;
  55.                 }
  56.                 else {
  57.                     f = false;
  58.                 }
  59.                 k = false;
  60.                 if (!f) {
  61.                     ++j;
  62.                 }
  63.                 continue;
  64.             }
  65.            
  66.             if (!f) {
  67.                 a[i].second[j].name.push_back(p);
  68.             }
  69.             else {
  70.                 gr = true;
  71.                 if (!k) {
  72.                     a[i].second[j].num = p - '0';
  73.                     k = true;
  74.                 }
  75.                 else {
  76.                     a[i].second[j].num *= 10;
  77.                     a[i].second[j].num += p - '0';
  78.                 }
  79.             }
  80.             if (a[i].second[j].name == "Box") {
  81.                 f = true;
  82.             }
  83.             else {
  84.                 f = false;
  85.             }
  86.  
  87.         }
  88.         ++i;
  89.     }
  90.     for (int idk = 0; a[idk].first.name != "" && idk < 100; ++idk) {
  91.         std::cout << a[idk].first.name << " " << a[idk].first.num << " ";
  92.         Dive(a, a[idk].first.num, false);
  93.     }
  94.     str.close();
  95. }
  96.  
Advertisement
Add Comment
Please, Sign In to add comment