Advertisement
a53

BalancedTernary

a53
Feb 6th, 2020
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void rec(int n)
  5. {
  6. if(n>0)
  7. {
  8. rec((n+1)/3);
  9. if(n%3==0)
  10. cout<<0;
  11. else
  12. if(n%3==1)
  13. cout<<1;
  14. else
  15. cout<<"T";
  16. }
  17. }
  18. int main()
  19. {
  20. int n;
  21. cin>>n;
  22. if(n)
  23. rec(n);
  24. else
  25. cout<<0;
  26. return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement