提交时间:2023-08-23 21:35:31

运行 ID: 99823

#include <bits/stdc++.h> using namespace std; struct tree{ char val; tree *left; tree *right; }; string a; void digui(tree *s,vector<char> &z){ if(s!=nullptr){ digui(s->left,z); digui(s->right,z); z.push_back(s->val); } } tree* dg(int i,int j){ if(i<j){ tree *tmp1 = dg(i, (i+j)/2); tree *tmp2 = dg((i+j)/2+1, j); tree *node = new(tree); node->left = tmp1; node->right = tmp2; char s1 = tmp1->val; char s2 = tmp2->val; if(s1==s2&&s1!='F') { node->val = s1; } else{ node->val = 'F'; } } else{ tree *node = new(tree); node->left = nullptr; node->right = nullptr; if(a[i]=='1') { node->val = 'I'; } else { node->val = 'B'; } return node; } } int main(){ int n; cin>>n; cin>>a; tree *root=dg(0,a.size()-1); vector<char> ss; digui(root,ss); for(int i = 0;i<ss.size();i++){ cout<<ss[i]; } cout<<endl; return 0; }