求解原视频:平衡三进制 求赞!100赞买个乒乓球拍!_哔哩哔哩_bilibili
求解程序:
cpp
using namespace std;
#include <iostream>
#include <cstring>
string work(int n)
{
if(n==0)return "";
if( n%3 == 2 || n%3 == -1 )return work((n+1)/3)+ "T";
else if( n%3 == 1 || n%3 == -2 )return work((n-1)/3)+"1";
else return work(n/3)+"0";
}
int main()
{
int n;
cin >> n;
string s_str=(n==0)?"0":work(n);
cout << s_str <<endl;
return 0;
}