Euclid_s Game實(shí)現(xiàn)(c++)歐基里得游戲代碼如下:
#include
bool Euclid_game(int num_a,int num_b)//求得兩個(gè)數(shù)勝負(fù)狀態(tài),返回true,為勝;返回
//false為負(fù)
{
if(num_a/num_b<2)
return !(Euclid_game(num_b,num_a-num_b));
else return true;
}
int main()
{
int n,m;
cout<<"two numbers:"< cin>>n>>m;//先后輸入兩個(gè)數(shù)字
if(Euclid_game(n,m))//若A先出,B后出,則直接將輸入的兩個(gè)數(shù)通過(guò)傳遞參數(shù)
//返回A的勝負(fù)狀態(tài),如果為true則輸出勝方為A,否則輸出勝方為B
cout<<"A"< else cout<<"B"< return 0;
}
#include
bool Euclid_game(int num_a,int num_b)//求得兩個(gè)數(shù)勝負(fù)狀態(tài),返回true,為勝;返回
//false為負(fù)
{
if(num_a/num_b<2)
return !(Euclid_game(num_b,num_a-num_b));
else return true;
}
int main()
{
int n,m;
cout<<"two numbers:"<
if(Euclid_game(n,m))//若A先出,B后出,則直接將輸入的兩個(gè)數(shù)通過(guò)傳遞參數(shù)
//返回A的勝負(fù)狀態(tài),如果為true則輸出勝方為A,否則輸出勝方為B
cout<<"A"<
}