斐波那契数列取石子游戏

#include <stdio.h>
int main()
{
int n,i;
int a[45]={2,3};
scanf("%d",&n);
for (i=2;i<45;i++)
a[i]=a[i-1]+a[i-2];
for(i=0;i<45;i++)
{
if(n==a[i])
printf("Bob!");
break;
}
if(i==45)
printf("Bob!");
return 0;
}

或c++版:

#include <iostream>
using namespace std;
int main()
{
int i;
__int64 n,fib[45] = {2,3};
for (i = 2;i < 45;i++)
fib[i] = fib[i-1] + fib[i-2];
while(cin >> n && n)
{
for(i = 0;i < 45;i++)
if(fib[i] == n)
{
cout << "Second win\n";
break;
}
if(i == 45)
cout << "First win\n";
}
return 0;
}

posted @ 2015-01-09 18:57  zach96  阅读(396)  评论(0编辑  收藏  举报