csp 201609-3 炉石传说

题意

在这里插入图片描述
在这里插入图片描述在这里插入图片描述

  • 测试结果
    在这里插入图片描述

思路

  • 英雄和随从用People表示,有生命值和攻击力
  • 棋盘board用2*8的People指针数组构成,初始化board[0][0]board[1][0]为英雄的属性
  • 按输入构成主程序框架,用plr表示当前玩家
  • “summon”操作时,先向后移动随从位置,再插入
  • “attack”操作时,更新生命值,分别判断。若随从生命值<=0,随从向前移;若被攻方英雄生命值<=0,且当前比赛没有结果,则记录plr
  • "end"操作时,plr=1-plr更新当前玩家
  • 最后按输出格式输出

代码

#include<iostream>
#include<string>
#include<vector>
using namespace std;


struct People{
	int hlth, atck;
	People(){}
	People(int h,int a):hlth(h),atck(a){}
};
People* board[2][8];
void clear(){
	for(int i=0;i<2;i++){
		for(int j=0;j<8;j++){
			board[i][j]=NULL;
		}
	}

	for(int i=0;i<2;i++)
		board[i][0] = new People(30,0);
	
}


int main(void){
	int n,plr=0,chess=-1;
	cin>>n;
	clear();
	while(n--){
		string action;
		cin>>action;
		if(action=="summon"){
			int pos,atk,hlth;
			cin>>pos>>atk>>hlth;
			//
			for(int j=7;j>pos;j--)
				board[plr][j] = board[plr][j-1];
			board[plr][pos] = new People(hlth,atk);
		}
		else if(action=="attack"){
			int attacker,defender;
			cin>>attacker>>defender;
			//
			board[plr][attacker]->hlth -= board[1-plr][defender]->atck;
			board[1-plr][defender]->hlth -= board[plr][attacker]->atck;
			//
			if(board[plr][attacker]->hlth <= 0){
				for(int j=attacker;j<7;j++)
					board[plr][j] = board[plr][j+1];
				board[plr][7] = NULL;
			}
			//
			if(board[1-plr][defender]->hlth <= 0){
				if(defender==0 && chess==-1)
					chess = plr;

				else if(defender!=0){
					for(int j=defender;j<7;j++)
						board[1-plr][j] = board[1-plr][j+1];
					board[1-plr][7] = NULL;
				}
			}
		}
		else if(action=="end"){
			//
			plr = 1-plr;
		}
	}

	//
	if(chess==-1) cout<<0<<endl;
	else if(chess==0) cout<<1<<endl;
	else if(chess==1) cout<<-1<<endl;
	//
	int p1=0;
	vector<int> v1;
	cout<<board[0][0]->hlth<<endl;
	for(int i=1;i<=7;i++){
		if(board[0][i]!=NULL){
			p1++;
			v1.push_back(board[0][i]->hlth);
		}
	}
	cout<<p1<<" ";
	for(auto h:v1) cout<<h<<" ";
	cout<<endl;
	//
	int p2=0;
	vector<int> v2;
	cout<<board[1][0]->hlth<<endl;
	for(int i=1;i<=7;i++){
		if(board[1][i]!=NULL){
			p2++;
			v2.push_back(board[1][i]->hlth);
		}
	}
	cout<<p2<<" ";
	for(auto h:v2) cout<<h<<" ";
	cout<<endl;


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值