Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string>
- using namespace std;
- int main()
- {
- int n;
- cin >> n;
- int *arr = new int[n-1];
- int max = -1;
- for (int i = 0; i < n-1; i++)
- {
- cin >> arr[i];
- if (arr[i] > max)
- max = arr[i];
- }
- int **tree = new int*[max];
- for (int i = 0; i < n; i++)
- tree[i] = new int[n];
- tree[0][0] = 0;
- for (int i = 0; i < max; i++)
- for (int j = 0; j < n-1; j++)
- {
- if (arr[j] == i+1)
- tree[i][j+1] = 1;
- else tree[i][j+1] = 0;
- }
- for (int i=0; i<max; i++)
- {
- for (int j=0; j<n; j++)
- {
- cout.width(3);
- cout << tree[i][j] << " ";
- }
- cout << endl;
- }
- cout << '1' << " ";
- for (int i = 0; i < max; i++)
- for (int j = 0; j < n; j++)
- {
- if (i%2 != 0 && tree[i][j] == 1)
- cout << j+1 << " ";
- if (i%2 == 0 && tree[i][n - j -1] == 1)
- cout << n-j << " ";
- }
- }
Add Comment
Please, Sign In to add comment