二进制字符串长度64位以内模板:
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <string.h>
using namespace std;
typedef unsigned long long ULL;
const int f=3;
const int N=64;
int main()
{
char ch;
int n;
ULL k;
scanf("%d",&n);
getchar();
while(n--)
{
char ans[N];
int i=0;
k=0;
while((ch=getchar())!='\n')
{
k<<=1;
k+=ch-'0';
}
if(k==0) //转化为f进制
printf("0\n");
else
{
while(k)
{
ans[i++]='0'+k%f;
k/=f;
}
while(i>0)
putchar(ans[--i]);
printf("\n");
}
}
return 0;
}