炉石传说

大模拟

#include<iostream>
#include<sstream>
#include<vector>

using namespace std;

const int N = 5010;
string dt[N];
int n;
struct mos { int atk, hp; };

int hp[2] = { 30,30 };
vector<mos>m[2];

void start() {
    stringstream ss;
    int type = 0;//0先手英雄,1后手英雄
    for (int i = 0; i < n; i++) {
        ss.clear();
        ss.str(dt[i]);
        string action;
        ss >> action;
        if (action == "summon") {
            int p, atk, hp;
            ss >> p >> atk >> hp;
            m[type].push_back({ atk,hp });
            if (m[type].size() >= p) {
                int t = m[type].size() - 1;
                while (t != p - 1) {
                    swap(m[type][t], m[type][t - 1]);
                    t--;
                }
            }
        }
        else if (action == "attack") {
            int p1, p2;
            ss >> p1 >> p2;
            if (p2 == 0) {
                hp[type ^ 1] -= m[type][p1 - 1].atk;
                if (hp[type ^ 1] <= 0)return;
            }
            else {
                m[type][p1 - 1].hp -= m[type ^ 1][p2 - 1].atk;
                m[type ^ 1][p2 - 1].hp -= m[type][p1 - 1].atk;
                if (m[type][p1 - 1].hp <= 0)m[type].erase(m[type].begin() + p1 - 1);
                if (m[type ^ 1][p2 - 1].hp <= 0)m[type ^ 1].erase(m[type ^ 1].begin() + p2 - 1);
            }

        }
        else if (action == "end") {
            type = type ^ 1;
        }
    }
}
int main() {
    cin >> n;
    getchar();
    for (int i = 0; i < n; i++) {
        string s;
        getline(cin, s);
        dt[i] = s;
    }
    start();
    if (hp[0] <= 0)cout << -1 << endl;
    else if (hp[1] <= 0)cout << 1 << endl;
    else cout << 0 << endl;
    for (int t = 0; t <= 1; t++) {
        cout << hp[t] << endl;
        cout<< m[t].size()<<' ';
        for (int i = 0; i < m[t].size(); i++) {
            cout << m[t][i].hp << ' ';
        }
        cout << endl;
    }
}

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值