#include int getHashIndex(std::string line) { int n = 0; while(true) { if(line[n] == '#') { return n; } n++; } return -1; } int decodeNumber(std::string line[], int ln) { int prev_index = getHashIndex(line[0]); int n = 1; for(int i = 1; i < ln; i++) { int index = getHashIndex(line[i]); if(index > prev_index) { n *= 2; } else { n = n * 2 + 1; } prev_index = index; } return n; } struct node { node *l; node *r; }; std::string encodeNumber(int n) { node root{}; node* cur = &root; int ll = 0,rl = 0; int cl = 0; int d = 1; while(n > 1) { node* nn = static_cast(malloc(sizeof(node))); if(n & 0x1) { cur->r = nn; cur = nn; cl++; if(cl > rl) { rl = cl; } } else { cur->l = nn; cur = nn; cl--; if(cl < ll) { ll = cl; } } n/=2; d++; } ll = abs(ll); std::cout<l != nullptr) { cur = cur->l; ll -= 1; rl += 1; } else if(cur->r != nullptr) { cur = cur->r; ll += 1; rl -= 1; } } for(int i = d-1; i >= 0; i--) { std::cout << s[i] << "\n"; } return ""; } int main() { int ln1,ln2; // read first number std::cin >> ln1; std::string s1[ln1]; for(int i = 0; i < ln1; i++) { std::cin >> s1[i]; } // read second number std::cin >> ln2; std::string s2[ln2]; for(int i = 0; i < ln2; i++) { std::cin >> s2[i]; } int n1 = decodeNumber(s1, ln1); int n2 = decodeNumber(s2, ln2); int n3 = n1 + n2; // ln3 = ln1; // s3 = s1; // std::cout << n3 << "\n"; encodeNumber(n3); // std::cout << s3; return 0; }