题目链接: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;
}
}
}