fork(3) download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. typedef struct node {
  5. int value;
  6. struct node *left;
  7. struct node *right;
  8. } Node;
  9.  
  10. Node* build_tree(int N) {
  11. if (N==-1) {
  12. return NULL;
  13. }
  14. Node *root = (Node*)malloc(sizeof(Node));
  15. root->left = build_tree(N-1);
  16. root->right = build_tree(N-1);
  17. return root;
  18. }
  19.  
  20. void set_leaf(Node *root, int M) {
  21. if (M==1) {
  22. scanf("%d", &(root->value));
  23. }
  24. else {
  25. set_leaf(root->left, M/2);
  26. set_leaf(root->right, M/2);
  27. }
  28. }
  29.  
  30. int read_leaf(Node *root, int i, int M){
  31. char a[10];
  32. for(int i=0; i<M; i++){
  33. a[i]=root->value;
  34. if(i<M/2){
  35. return a[i];
  36. }
  37. else{
  38. return a[i];
  39. }
  40. }
  41. }
  42.  
  43. int main() {
  44. int N, M;
  45. scanf("%d%d", &N, &M);
  46. Node *root = build_tree(N);
  47.  
  48. set_leaf(root, M);
  49. for (int i = 0 ; i < M; i++)
  50. printf("%d\n", read_leaf(root, i, M));
  51. return 0;
  52. }
  53.  
Internal error #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty