欧几里得游戏

题目链接:https://vjudge.net/problem/UVA-10368

题目

给出两个数,两个人(Stan,Ollie)做一个游戏,每次有stan开始操作,每次操作可以从最大的数中取走若干个小的数,即a-kb,a为比较大的数,b为比较小的数,kb为取走的值,k必须为整数,并且kb≤a。如果不能顺利执行操作,则对手胜利。

Input

The input consists of a number of lines. Each line contains two positive integers giving the starting two

numbers of the game. Stan always starts.

Output

For each line of input, output one line saying either `Stan wins' or `Ollie wins' assuming that both

of them play perfectly. The last line of input contains two zeroes and should not be processed.

Sample Input

34 12

15 24

0 0

Sample Output

Stan wins

Ollie wins

代码

#include<iostream>
using namespace std;
int main()
{
	int a,b,k,t;
	while(cin>>a>>b&&(a||b))
	{
		 k=1;
		if(a==b)
		{
			cout<<"Stan wins"<<endl;
		}
		else
		{
			while(a!=b)
			{
				if(a<b)
				swap(a,b);
				k++;
				if(a/b!=1)
				break;
				a%=b;
			}
			if(k%2==0)
			{
				cout<<"Stan wins"<<endl;
			}
			else
			cout<<"Ollie wins"<<endl;
		}
		
	}
} 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值