您的答案為: 1
正確答案為: 1 = 1 (fib)
#include<iostream>
using namespace std;
int main(){
int n;
cin>>n;
int fib[43];
fib[0] = 1;
fib[1] = 2;
for(int i=2;i<43;i++){
fib[i] = fib[i-1]+fib[i-2];
}
int num;
for(int i=0;i<n;i++){
cin>>num;
int s[43]={0};
int temp = num;
if(num>fib[42]){
s[42] = 1;
num -= fib[42];
}
cout<<num<<'\n';
for(int j=41;j>=0;j--){
if(num>=fib[j]&&s[j+1]==0){
num -= fib[j];
s[j] = 1;
}
else{
s[j] = 0;
}
if(num==0){
break;
}
}
int count=0;
for(int j=42;j>=0;j--){
if(s[j]==1){
break;
}
else{
count += 1;
}
}
cout<<temp<<" = ";
for(int j=43-count-1;j>=0;j--){
cout<<s[j];
}
cout<<" (fib)"<<'\n';
}
}
cout<<num<<'\n';
這行刪掉