Created
July 17, 2016 09:00
-
-
Save TheoKlein/0d1e23bce7b5e1b7bad484926b6e302d to your computer and use it in GitHub Desktop.
ZeroJudge a134
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <cmath> | |
| using namespace std; | |
| int fib( int * ); | |
| int main() { | |
| int n; | |
| cin >> n; | |
| while( n-- > 0 ){ | |
| int num; | |
| cin >> num; | |
| cout << num << " = "; | |
| int length = fib(&num) , result[length + 1]; | |
| for(int i = 0 ; i < length ; ++i) | |
| result[i] = 0; | |
| result[length] = 1; | |
| while(num > 0) | |
| result[fib(&num)] = 1; | |
| for(int i = length; i >= 0 ; --i) | |
| cout << result[i]; | |
| cout << " (fib)" << endl; | |
| } | |
| } | |
| int fib( int *num ){ | |
| int fib[50] = { 0 } , i = 2; | |
| fib[0] = 0 , fib[1] = 1 , fib[2] = 1; | |
| while(fib[i] <= *num){ | |
| fib[i + 1] = fib[i] + fib[i - 1]; | |
| i++; | |
| } | |
| *num -= fib[i - 1]; | |
| return i - 3; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment