-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTAP2014B.cpp
More file actions
50 lines (47 loc) · 973 Bytes
/
TAP2014B.cpp
File metadata and controls
50 lines (47 loc) · 973 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin>>t;
while(t--)
{
int n,temp,c=0,i,j;
cin>>n;
int arr[1000]={0};
temp=n;
for(i=0;temp;i++)
{
arr[i]=temp%3;
temp=temp/3;
}
//reverse(arr,arr+i-1);
//for(j=1;j<i;j++)cout<<arr[j];cout<<endl;
for(j=1;1;j++)
{
if(j>=i&&arr[j]==0)
break;
arr[j+1]+=arr[j]/3;
arr[j]=arr[j]%3;
if(arr[j]==2)
{
//cout<<j<<endl;
arr[j+1]++;
arr[j]=-1;
}
}
//cout<<j<<endl;
reverse(arr,arr+j);
for(i=0;i<j;i++)
{
if(arr[i]==1)
cout<<"+";
else if(arr[i]==-1)
cout<<"-";
else if(arr[i]==0)
cout<<"0";
}
cout<<endl;
}
// your code goes here
return 0;
}