CCF CSP 201609-3 满分AC

# include<stdio.h>
# include<stdlib.h>
# include<iostream>
# include<string>
# include<sstream>
# include<vector>
using namespace std;

struct Summon
{	int health;
	int attack;
};
vector<Summon>  player[2];//0是先手玩家,1是后手玩家 
int main()
{
	//freopen("data.txt","r",stdin);
	int n;
	cin>>n;
	getchar();
	
	int player_order = 0;//用来表示先手玩家与后手玩家的操作
	stringstream ss;
	string temp;
	
	//初始化英雄攻击力和血量
	Summon temp_s;
	temp_s.attack = 0;
	temp_s.health = 30;
	player[0].push_back(temp_s);
	player[1].push_back(temp_s);	
	while(n--)
	{
		getline(cin,temp);
		if(temp == "end")
		{
			
			player_order++;			
			continue;
		}
		else
		{
			ss.str(temp);
			ss>>temp;
			int po = player_order & 1;//取余操作,获得该回合操作玩家的编号 
			int po_com = 1 - po;//对手编号 
			if(temp=="summon")
			{
				int pos;				
				ss>>pos>>temp_s.attack>>temp_s.health;
				ss.clear();			
				vector<Summon>::iterator it = player[po].begin();
				player[po].insert(it+pos,temp_s);			 
			}
			else if(temp == "attack")
			{
				int attacker;
				int defender;
				ss>>attacker>>defender;
				ss.clear();				
				player[po][attacker].health -= player[po_com][defender].attack;
				player[po_com][defender].health -= player[po][attacker].attack;			
				if(player[po][attacker].health<=0)
				{
					vector<Summon>::iterator it = player[po].begin();
					player[po].erase(it+attacker);
				}
				if(defender!=0&&player[po_com][defender].health<=0)
				{
					vector<Summon>::iterator it = player[po_com].begin();
					player[po_com].erase(it+defender);
				}
			}
		} 
	}
	int win=0; 	
	if(player[0][0].health <= 0)
		win = -1;
	else if(player[1][0].health <= 0)
		win = 1;	
	
	int num_0,num_1;
	num_0 = player[0].size()-1;
	num_1 = player[1].size()-1;	
	cout<<win<<endl;	
	cout<<player[0][0].health<<endl;
	cout<<num_0<<" ";
	for(int i=1;i<=num_0;i++)
		cout<<player[0][i].health<<" ";
	cout<<endl;
	
	cout<<player[1][0].health<<endl;
	cout<<num_1<<" ";
	for(int i=1;i<=num_1;i++)
		cout<<player[1][i].health<<" ";	 
	return 0;
} 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值