• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
crucio
博客园    首页    新随笔    联系   管理    订阅  订阅
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;
}
*/

 

posted on 2017-03-27 18:08  crucio  阅读(207)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3