CCF CSP 201609-3 炉石传说

题意

题目链接:http://118.190.20.162/view.page?gpid=T45
在这里插入图片描述
简要题意:模拟炉石传说中召唤随从、随从的攻击。

解题思路

一道简单的模拟,使用一个变量cur来记录当前的玩家,用一个结构体数组来记录当前场上的随从,之后按照题目要求进行随从召唤后的右移和随从死亡后的左移即可。

代码

#include <iostream>
#include <string>
using namespace std;
struct Servent{
    int hp, atk;
    Servent operator=(const Servent &a){
        hp = a.hp;
        atk = a.atk;
        return *this;
    }
}s[2][8];
int cnt[2];
int n, cur;
int hp[2] = {30, 30};
int main(){
    cin >> n;
    for(int i = 0; i < n; ++i){
        string op;
        int a, b, c;
        cin >> op;
        if(op == "summon"){
            cin >> a >> b >> c;
            if(cnt[cur] >= a)
                for(int k = cnt[cur] + 1; k > a; k--)
                    s[cur][k] = s[cur][k - 1];
            s[cur][a].hp = c;
            s[cur][a].atk = b;
            cnt[cur]++;
        }else if(op == "attack"){
            cin >> a >> b;
            if(b == 0){
                hp[1 - cur] -= s[cur][a].atk;
                if(hp[1 - cur] <= 0) break;
            }
            else{
                s[cur][a].hp -= s[1 - cur][b].atk;
                s[1 - cur][b].hp -= s[cur][a].atk;
                if(s[cur][a].hp <= 0){
                    for(int k = a; k < cnt[cur]; ++k)
                        s[cur][k] = s[cur][k + 1];
                    cnt[cur]--;
                }
                if(s[1 - cur][b].hp <= 0){
                    for(int k = b; k < cnt[1 - cur]; ++k)
                        s[1 - cur][k] = s[1 - cur][k + 1];
                    cnt[1 - cur]--;
                }
            }
        }else if(op == "end")
            cur = 1 - cur;
    }
    if(hp[0] > 0 && hp[1] > 0)
        cout << 0 << endl;
    else if(hp[0] < 0) cout << -1 << endl;
    else cout << 1 << endl;
    cout << hp[0] << endl;
    cout << cnt[0];
    for(int i = 1; i <= cnt[0]; i++)
        cout << ' ' << s[0][i].hp;
    cout << endl;
    cout << hp[1] << endl;
    cout << cnt[1];
    for(int i = 1; i <= cnt[1]; i++)
        cout << ' ' << s[1][i].hp;
    cout << endl;
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值