Baby_gin

#include <iostream>
using namespace std;
int map[10];
char number[6];
int go;
bool baby_gin(char* number){
    for(int i=0;i<10;i++) map[i]=0;
    for(int i=0;i<6;i++){
        map[number[i]-‘0‘]++;
        if(map[number[i]-‘0‘]==3)map[number[i]-‘0‘]=0;
    }
    for(int i=0;i<8;i++){
        if(map[i]!=0){
            map[i+1]-=map[i];
            map[i+2]-=map[i];
            map[i]=0;
        }
    }
    for(int i=0;i<10;i++){
        if(map[i]!=0)return false;
    }
    return true;
}
int main(){
    while(true){
        cout<<"Input 6 Numbers:"<<endl;
        for(int i=0;i<6;i++)cin>>number[i];
        if(baby_gin(number))cout<<"Baby_gin!!!\n";
        else cout<<"Lose\n";
        cout<<"Play the game again?<1-yes/2-no>: ";
        cin>>go;
        cout<<endl;
        if(go==2)break;
    }
    return 0;
 }

/*
#include <iostream>
using namespace std;
int index[10];
char number[6];
int go;
bool isBaby_gin(char* number){
    for(int i=0;i<10;i++)index[i]=0;
    for(int i=0;i<6;i++){
        index[number[i]-‘0‘]++;
        if(index[number[i]-‘0‘]==3)index[number[i]-‘0‘]=0;
    }
    for(int i=0;i<8;i++)
        if(index[i]!=0){
            index[i+1]-=index[i];//index[i+1]=inedex[i+1]-index[i]
            index[i+2]-=index[i];
            index[i]=0;
            //112233  123456  566778 667789
        }
    for(int i=0;i<10;i++)
        if(index[i]!=0)return false;
    return true;
}

int main(){
    while(true){
        cout<<"Input 6 Numbers: ";
        for(int i=0;i<6;i++)cin>>number[i];
        if(isBaby_gin(number))cout<<"Baby gin !!!\n";
        else cout<<"Lose\n";
        cout<<"Play the game again?<1-yes/2-no>: ";
        cin>>go;
        cout<<endl;
        if(go==2)break;
    }
    return 0;
}
*/
时间: 2024-12-19 14:21:04

Baby_gin的相关文章