Card Game for Three

本文介绍了一个简单的模拟算法实现案例——三人打牌游戏。通过使用C++中的queue数据结构来模拟游戏过程,实现了根据游戏规则进行轮流出牌直到决出胜者的过程。文章提供了完整的代码实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目链接:http://exam.upc.edu.cn/problem.php?cid=1372&pid=11

题意:ABC三人打牌,他们只能出第一张牌,牌的内容说明下一回合是谁出牌。最后的人赢。

这个就是模拟,利用queue来模拟

#include<bits/stdc++.h>
using namespace std;
char s[4][1000];
int main()
{
    for(int i=0;i<3;i++){
        scanf("%s",s[i]);
    }
    queue<char>q[3];
    for(int i=0;i<3;i++){
        for(int j=0;j<strlen(s[i]);j++){
            q[i].push(s[i][j]);
        }
    }
    char tmp='a',t='a';
    while(1){
        //cout<<tmp<<endl;
        t=tmp;
        tmp=q[tmp-'a'].front();
        q[t-'a'].pop();
        if(q[tmp-'a'].empty()){
            printf("%c\n",tmp-32);
            break;
        }
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值