#include<iostream>
#include<cmath>
using namespace std;
int x;
//将数十进制x转化为三进制,并且每一位前面都设为'+';
string to_three(int x){
string s;
while(x){
s.push_back('+');
s.push_back(x % 3 + '0');
x /= 3;
}
return s;
}
int main(){
cin >> x;
string str = to_three(x);
//cout << str << endl;
//三进制只保留0和1, 将三进制中含有2的的位变为-1,并且向高位进1 (因为2*3^n = +1 * 3^n+1 + -1 * 3^n)
int len = str.length();
for(int i = 1; i <= len / 2; i++){
if(str[2*i - 1] == '2'){
str[2*i - 2] = '-';
str[2*i - 1] = '1';
if(2*i + 1 > len) str.push_back('+'), str.push_back('1');
else str[2*i + 1]++;
}
else if(str[2*i - 1] == '3'){
str[2*i - 1] = '0';
if(2*i + 1 > len) str.push_back('+'), str.push_back('1');
else str[2*i + 1]++;
}
}
//cout << str << endl;
//从高位开始输出
len = str.length();
for(int i = len - 2; i >= 0; i -= 2){
if(str[i + 1] - '0' != 0){
if(i != len - 2 && str[i] == '+') cout << '+';
else if(i != len - 2) cout << '-';
cout << (int)pow(3, i / 2);
}
}
return 0;
}
#我的实习求职记录##笔试#