uva 170 Clock Patience

 Clock Patience小游戏,百度可查到,可以下载玩

#include <iostream>
#include <queue>

using namespace std;

struct Clock {//第一个字符大写比较好
    char charrank;
    char charsuit;
    bool boolface;
    int binarytoint() {
          switch(charrank) {
          case 'A': return 1;
          case 'T': return 10;
          case 'J': return 11;
          case 'Q': return 12;
          case 'K': return 13;
          default : return int(charrank - '0');
          }
    }
};

class ClockPat {
private:
    queue<Clock> qclock[13];
    int walkstep;
    Clock steplast;
public:
    void initial();
    void readClock(char first);
    void computing();
    void outResult();
};
void ClockPat::initial() {
   for(int i = 0;i < 13;i++) {
    while(!qclock[i].empty()) {
        qclock[i].pop();
    }
   }
}
void ClockPat::readClock(char first) {
    Clock Clo;
    for(int i = 0; i < 4; i++) {
        for(int j = 0; j < 13; j++) {
            if((i == 0) && (j == 0)) {
                Clo.charrank = first;
                cin >> Clo.charsuit;
                Clo.boolface = true;
            }
            else {
                cin >> Clo.charrank >> Clo.charsuit;
                Clo.boolface = true;
            }
            qclock[12 -j].push(Clo);
        }
    }
}
void ClockPat::computing() {
    int ff = 12;
    walkstep = 0;
    while(qclock[ff].front().boolface) {
        steplast = qclock[ff].front();
        qclock[ff].pop();
        ff = steplast.binarytoint() - 1;
        steplast.boolface = false;
        walkstep++;
        qclock[ff].push(steplast);
    }
}
void ClockPat::outResult() {
    cout<<walkstep/10<<walkstep%10<<',';
    cout<<steplast.charrank<<steplast.charsuit<<endl;
}
int main()
{
   ClockPat cl;
   char cc;
   while((cin>>cc) && (cc != '#')) {
    cl.initial();
    cl.readClock(cc);
    cl.computing();
    cl.outResult();
   }

    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值