挑程上的题
当a >= 2b时 :胜
当 a > b&&a < 2b 时 :a -= b模拟
当 a == b时 :胜
2b计算过程中溢出了......
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<algorithm>
#define mem(a,x) memset(a,x,sizeof(a))
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
/*
挑程上的题
当a >= 2b时 :胜
当 a > b&&a < 2b 时 :a -= b模拟
当 a == b时 :胜
2b计算过程中溢出了......
*/
int main()
{
int a,b;
while (cin>>a>>b){
if (a==0&&b==0) break;
bool first = true;
while (1){
if (b>a) swap(a,b);
if (a == b) break;
if (a-b >= b) break;//写成a>=2*b会WA
//2b计算过程中溢出了......
a -= b;
first = !first;
}
if (first) puts("Stan wins");
else puts("Ollie wins");
}
return 0;
}
java :
//package acm.poj2348;
import java.util.*;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
@SuppressWarnings("resource")
Scanner in = new Scanner (System.in);
while (in.hasNext()){
int a = in.nextInt();
int b = in.nextInt();
if (a==0&&b==0) break;
boolean first = true;
while (true){
if (b > a) {
a^=b;b^=a;a^=b;
}
if (a == b) break;
if (a-b>=b) break;
a -= b;
first = !first;
}
if (first)System.out.println("Stan wins");
else System.out.println("Ollie wins");
}
}
}