problem statement is here
#include<stdio.h>
int main() {
int t,y,z,n,ar[10000],i;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
z=0;
while(n){
ar[z]=n%3;
z++;
n/=3;
}
ar[z]=0;
for(i=0;i<=z;i++){
if(ar[i]==2){
ar[i]=-1;
ar[i+1]++;
}else if(ar[i]==3){
ar[i]=0;
ar[i+1]++;
}
}
y=0;
for(i=z;i>=0;i--){
if(ar[i]!=0){
y=1;
if(ar[i]==1)
printf("+");
else if(ar[i]==-1)
printf("-");
}
else if(y==1)
printf("0");
}
printf("\n");
}
return 0;
}
No comments:
Post a Comment