Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <string>
- #include <utility>
- struct box {
- std::string name = "";
- int num = 0;
- bool obj = false;
- };
- void Dive(std::vector<std::pair<box, std::vector<box>>>& a, int n, bool depth) {
- for (int j = 0;; ++j) {
- if (a[j].first.num == n) {
- n = j;
- break;
- }
- }
- for (int i = 0; a[n].second[i].name != "" && i < 100; ++i) {
- if (!a[n].second[i].obj) {
- std::cout << a[n].second[i].name << " ";
- }
- else {
- Dive(a, a[n].second[i].num, true);
- }
- }
- if (!depth) {
- std::cout << "\n";
- }
- return;
- }
- int main() {
- std::fstream str;
- str.open("Input.txt");
- if (!str.is_open()) {
- std::cout << "FAILED TO OPEN FILE 1";
- return 0;
- }
- std::vector<std::pair<box, std::vector<box>>> a(100);
- for (int ind = 0; ind < 100; ++ind) {
- a[ind].second.resize(100);
- }
- int i = 0;
- while (!str.eof()) {
- str >> a[i].first.name;
- str >> a[i].first.num;
- int j = -1;
- bool f = false, k = false, gr = false;
- for (char p; (p = str.get()) != '\n' && !str.eof();) {
- if (p == ' ') {
- if (f && !gr) {
- a[i].second[j].obj = true;
- }
- else {
- f = false;
- }
- k = false;
- if (!f) {
- ++j;
- }
- continue;
- }
- if (!f) {
- a[i].second[j].name.push_back(p);
- }
- else {
- gr = true;
- if (!k) {
- a[i].second[j].num = p - '0';
- k = true;
- }
- else {
- a[i].second[j].num *= 10;
- a[i].second[j].num += p - '0';
- }
- }
- if (a[i].second[j].name == "Box") {
- f = true;
- }
- else {
- f = false;
- }
- }
- ++i;
- }
- for (int idk = 0; a[idk].first.name != "" && idk < 100; ++idk) {
- std::cout << a[idk].first.name << " " << a[idk].first.num << " ";
- Dive(a, a[idk].first.num, false);
- }
- str.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment