CCF CSP201609-3炉石传说(c++100)

CCF CSP201609-3炉石传说

在这里插入图片描述
简单模拟

#include<iostream>
#include<string>
using namespace std;
struct Hero{
	int attack,health;
}A[8],B[7];
int main(){
	A[0].attack = B[0].attack = 0;
	A[0].health = B[0].health = 30;
	int n;
	cin>>n;
	bool flag = true;//true标志玩家A,false标志玩家B 
	int winner = 0,summon1 = 0, summon2 = 0;
	for(int i = 0; i < n; i++){
		string s;
		cin>>s;
		if(s == "summon"){
			int position,attack,health;
			cin>>position>>attack>>health;
			if(flag){
				for(int j = 6; j >= position; j--){
					A[j+1] = A[j];
				}
				A[position].attack = attack;
				A[position].health = health;
				summon1++;
			}else{
				for(int j = 6; j >= position; j--){
					B[j+1] = B[j];
				}
				B[position].attack = attack;
				B[position].health = health;
				summon2++;
			}
		}
		else if(s == "attack"){
			int attacker,defender;
			cin>>attacker>>defender;
			if(flag){
				A[attacker].health -= B[defender].attack;
				B[defender].health -= A[attacker].attack;
				if(A[attacker].health <= 0 && attacker != 0){
					for(int j = attacker; j < 7; j++){
						A[j] = A[j+1];
					}
					A[7].attack = A[7].health = 0;
					summon1--;
				}
				if(B[defender].health <= 0 && defender != 0){
					for(int j = defender; j < 7; j++){
						B[j] = B[j+1];
					}
					B[7].attack = B[7].health = 0;
					summon2--;
				}
			}
			else{
				B[attacker].health -= A[defender].attack;
				A[defender].health -= B[attacker].attack;
				if(A[defender].health <= 0 && defender != 0){
					for(int j = defender; j < 7; j++){
						A[j] = A[j+1];
					}
					A[7].attack = A[7].health = 0;
					summon1--;
				}
				if(B[attacker].health <= 0 && attacker != 0){
					for(int j = attacker; j < 7; j++){
						B[j] = B[j+1];
					}
					B[7].attack = B[7].health = 0;
					summon2--;
				}
			}
			if(A[0].health <= 0) {
				winner = -1;
				break;
			}
			if(B[0].health <= 0) {
				winner = 1;
				break;
			}
		}
		else if(s == "end"){
			flag = !flag;
		}
//		for(int j = 1; j <= 7; j++){
//			cout<<A[j].health<<":"<<A[j].attack<<"   ";
//		}
//		cout<<endl;
//		for(int j = 1; j <= 7; j++){
//			cout<<B[j].health<<":"<<B[j].attack<<"   ";
//		}
//		cout<<endl;
	}
	cout<<winner<<endl;
	cout<<A[0].health<<endl;
	cout<<summon1;
	for(int i = 1; i<= 7; i++){
		if(A[i].health > 0) {
			cout<<" "<<A[i].health;
		}
	}
	cout<<endl;
	cout<<B[0].health<<endl;
	cout<<summon2;
	for(int i = 1; i<= 7; i++){
		if(B[i].health > 0) cout<<" "<<B[i].health;
	}
	cout<<endl;
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值