[OpenJudge-NOI]取石子游戲

代碼

#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;

int ans;
int Check(int a,int b) {
    ans++;
    if(a==b){
        if(ans%2==1) return 1;else return 0;
    }   
    if(a/b>=2){
        if(ans%2==1) return 1;else return 0;
    }
    return Check(min(a,b),max(a,b)-min(a,b));
}

int main() {
    int a,b;
    while(scanf("%d%d",&a,&b)!=EOF&&a!=0&&b!=0) {
        if(a<b) swap(a,b);
        if(b==0){
            printf("lose\n");
            continue;
        }
        ans=0;
        if(Check(a,b)) printf("win\n");else printf("lose\n");
    }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章