CSP 201609-3 炉石传说

简单的模拟题

#include <bits/stdc++.h>
using namespace std;
int n;
struct fllower {
  int id;
  int health;
  int attack;
};
struct player{
  int cnt = 0;
  int id = 1;
  int health = 30;
  int attack = 0;
  fllower f[10];
};
int winner = -1;
int mod = 0;
player players[2];
void solveSummon() {
  int position, attack, health;
  cin >> position >> attack >> health;
  players[mod].cnt++;
  for (int i = 6; i >= position; i--) {
    players[mod].f[i + 1] = players[mod].f[i];
    players[mod].f[i + 1].id = i + 1;
  }
  players[mod].f[position].id = position;
  players[mod].f[position].health = health;
  players[mod].f[position].attack = attack;
}
void solveAttack() {
  int attacker, defender;
  cin >> attacker >> defender;
  int oa;
  int ta = players[mod].f[attacker].attack;
  if (defender == 0) {
    oa = players[!mod].attack;
    players[!mod].health -= ta;
    if (players[!mod].health <= 0) {
      winner = mod;
    }
  } else {
    oa = players[!mod].f[defender].attack;
    players[!mod].f[defender].health -= ta;
    if (players[!mod].f[defender].health <= 0) {
      players[!mod].cnt--;
      for (int i = defender; i <= 6; i++) {
        players[!mod].f[i] = players[!mod].f[i + 1];
        players[!mod].f[i].id = i;
      }
    }
  }
  players[mod].f[attacker].health -= oa;
  if (players[mod].f[attacker].health <= 0) {
    players[mod].cnt--;
    for (int i = attacker; i <= 6; i++) {
      players[mod].f[i] = players[mod].f[i + 1];
      players[mod].f[i].id = i;
    }
  }
}
void readPlayer() {
  string action;
  cin >> action;
  if (action == "summon") {
    solveSummon();
  } else if (action == "attack") {
    solveAttack();
  } else {
    mod = !mod;
  }
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    readPlayer();
  }
  if (winner == -1) {
    cout << 0 << '\n';
  } else if (winner == 0) {
    cout << 1 << '\n';
  } else {
    cout << -1 << '\n';
  }
  cout << players[0].health << '\n';
  cout << players[0].cnt << ' ';
  for (int i = 1; i <= players[0].cnt; i++) {
    cout << players[0].f[i].health << ' ';
  }
  cout << '\n';
  cout << players[1].health << '\n';
  cout << players[1].cnt << ' ';
  for (int i = 1; i <= players[1].cnt; i++) {
    cout << players[1].f[i].health << ' ';
  }
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值