Advertisement
yuawn

algo2017_week8_Ternary

Nov 23rd, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.41 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define pb push_back
  4. #define fo(n) for(int i=0;i<n;i++)
  5.  
  6. int main(){
  7.  
  8.     int n;
  9.    
  10.     while( cin >> n && n >= 0 ){
  11.         vector<int> p;
  12.        
  13.         if( !n ){
  14.             cout << '0' << endl;
  15.             continue;
  16.         }
  17.        
  18.         while( n ){
  19.             int tmp = n % 3;
  20.             p.pb( tmp );
  21.             n /=3;
  22.         }
  23.        
  24.         for( int i = p.size() - 1 ; i > -1 ; --i ) cout << p[i];
  25.         cout << endl;
  26.     }
  27.  
  28.     return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement