Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pt4.h"
- #include <string>
- #include <fstream>
- using namespace std;
- ofstream out;
- struct Tree
- {
- Tree* left = nullptr;
- Tree* right= nullptr;
- int data = 0;
- };
- Tree* Init(int N, int data)
- {
- Tree* Node=new Tree;
- Node->data = data;
- if (N == 0) return nullptr;
- if (N == 1) return Node;
- Node->left = Init(N-1, 1);
- Node->right = Init(N-1, -1);
- return Node;
- }
- void Walker(Tree* tree, string path, int sum)
- {
- if (tree->left == nullptr)
- {
- if (sum==0)
- out << path << endl;
- return;
- }
- else
- Walker(tree->left, path + "A", sum + 1);
- if (tree->right == nullptr)
- {
- if (sum == 0)
- out << path << endl;
- return;
- }
- else
- Walker(tree->right, path + "B", sum - 1);
- return;
- }
- void Solve()
- {
- Task("Recur27");
- Tree* tree = nullptr;
- string filename; int N;
- pt >> N >> filename;
- out.open(filename);
- tree = Init(N+1, 0);
- Walker(tree, "C", 0);
- out.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement