Created
July 17, 2017 14:19
-
-
Save na5imuzzaman/afb3e67cec17ca202d1ee8fe642b11b2 to your computer and use it in GitHub Desktop.
UVa --> 11185 - Ternary
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Nasim */ | |
#include<bits/stdc++.h> | |
using namespace std; | |
int main() | |
{ | |
long long int n; | |
char str[150]; | |
while(1) | |
{ | |
cin>>n; | |
if (n<0) | |
break; | |
int m = 0; | |
while(1) | |
{ | |
if (n<3) | |
{ | |
if (n==2) | |
str[m++] = '2'; | |
else if (n==1) | |
str[m++] = '1'; | |
else if (n==0) | |
str[m++] = '0'; | |
break; | |
} | |
if (n%3==0) | |
str[m++] = '0'; | |
else if (n%3==1) | |
str[m++] = '1'; | |
else if(n%3==2) | |
str[m++] = '2'; | |
n = n/3; | |
} | |
for(int i=m-1; i>=0; i--) | |
{ | |
cout<<str[i]; | |
} | |
cout<<"\n"; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment