fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. #define N 8
  5. int arr[2*N];
  6. int n=0;
  7. void buildt()
  8. {
  9. for(int i=n;i>0;i--)
  10. {
  11. arr[i]=arr[2*i]+arr[2*i+1];
  12. }
  13. return;
  14. }
  15. void printt()
  16. {
  17. for(int i=0;i<2*n;i++)
  18. {
  19. cout<<"i= "<<i<<":"<<arr[i];
  20. if(i==n)
  21. cout<<endl;
  22. }
  23. cout<<endl;
  24. }
  25.  
  26. int main()
  27. {
  28. cin>>n;
  29. for(int i=0;i<n;i++)
  30. {
  31. cin>>arr[i+n];
  32. }
  33. buildt();
  34. printt();
  35. return 0;
  36. }
Success #stdin #stdout 0s 16064KB
stdin
8 0 1 2 3 4 5 6 7
stdout
i= 0:0i= 1:28i= 2:6i= 3:22i= 4:1i= 5:5i= 6:9i= 7:13i= 8:0
i= 9:1i= 10:2i= 11:3i= 12:4i= 13:5i= 14:6i= 15:7