月模拟题-炉石传说

炉石传说

题目

在这里插入图片描述

思路

这题比较直白,就是要仔细看题。。。attacker攻击对方随从时不是hp减去自己的攻击值,而是减去对方的攻击值。
使用vector,刚好英雄在0号位,插入删除和这题十分契合。

提交结果

在这里插入图片描述

代码

#include <iostream>
#include <cmath>
#include <vector>
#include <cstring>
#include <algorithm>

using namespace std;
struct player {
	int hp, atk;
	player() {}
	player(int hp_, int atk_) :hp(hp_), atk(atk_) {}
};

vector<player> p[2];
int cnt, pos_, atk_, atker_, dfer_, hp_, flag = 0;

void option_summon(int pos, int hp, int atk, int x) {
	p[x].insert(p[x].begin() + pos, { hp,atk });
}

void option_atk(int atker, int dfer, int x) {
	int y = (x + 1) % 2;
	p[x][atker].hp -= p[y][dfer].atk;
	p[y][dfer].hp -= p[x][atker].atk;
	if (p[x][atker].hp <= 0) p[x].erase(p[x].begin() + atker);
	if (dfer!=0 && p[y][dfer].hp <= 0) p[y].erase(p[y].begin() + dfer);
}


int main() {
	cin >> cnt;
	p[0].push_back({ 30,0 });
	p[1].push_back({ 30,0 });
	for (int kkk = 0; kkk < cnt; kkk++) {
		string option;
		cin >> option;
		if (option == "summon") {
			cin >> pos_ >> atk_ >> hp_;
			option_summon(pos_, hp_, atk_, flag);
		}
		else if (option == "attack") {
			cin >> atker_ >> dfer_;
			option_atk(atker_, dfer_, flag);
		}
		else if (option == "end") flag = (flag + 1) % 2;
	}

	if (p[1][0].hp <= 0) cout << 1 << endl;
	else if (p[0][0].hp <= 0) cout << -1 << endl;
	else cout << 0 << endl;

	cout << p[0][0].hp<<endl;
	cout << p[0].size() - 1 << ' ';
	for (int i = 1; i <= p[0].size() - 1; i++) {
		cout << p[0][i].hp;
		if (i != p[0].size() - 1) cout << ' ';
	}
	cout << endl;

	cout << p[1][0].hp<<endl;
	cout << p[1].size() - 1 << ' ';
	for (int i = 1; i <= p[1].size() - 1; i++) {
		cout << p[1][i].hp;
		if (i != p[1].size() - 1) cout << ' ';
	}
	cout << endl;
	return 0;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值