Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- void preOrder(int x, int n){
- if(x > n){
- return;
- }
- cout << x << ' ';
- preOrder(x << 1, n);
- preOrder(x << 1 | 1, n);
- }
- int main(){
- int Q;
- scanf("%d", &Q);
- for(int q = 1; q <= Q; ++q){
- int n;
- scanf("%d", &n);
- cout << "Case #" << q << ": ";
- preOrder(1, n);
- cout << '\n';
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment