UVA 11185 Ternary



#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long int i,j,k,l,n,m,a[10000];

    //freopen("11185.txt","r",stdin);
    //freopen("11185out.txt","w",stdout);
    while(cin>>n)
    {
        if(n<0)
        {
            break;
        }

        if(n==0)
        {
            cout<<0<<endl;
        }
        else
        {
             i=1;
             while(n>0)
             {
                 a[i]=n%3;
                 n=n/3;
                 i++;

             }

              for(j=i-1;j>=1;j--)
              {

                  cout<<a[j];

              }
              cout<<endl;
         }




    }

    return 0;
}

Download Coding Interview Book and Get More Tutorials for Coding and Interview Solution: Click Here

Download System Design Interview Book and Get More Tutorials and Interview Solution: Click Here

Do you need more Guidance or Help? Then Book 1:1 Quick Call with Me: Click Here

Share on Google Plus

About Ashadullah Shawon

I am Ashadullah Shawon. I am a Software Engineer. I studied Computer Science and Engineering (CSE) at RUET. I Like To Share Knowledge. Learn More: Click Here
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment