一道模拟题,指令都不难处理,要是用Vector来做的话就更方便了
省去了很多操作
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
struct juese
{
int attack;
int hp;
juese(){};
juese(int a,int b)
{
attack=a;
hp=b;
}
};
vector<juese> a,b;
int main()
{
int n,p,q,r;
string s;
a.push_back(juese(0,30));
b.push_back(juese(0,30));
scanf("%d",&n);
int flag=0,t=0;
for(int i=0;i<n;i++)
{
cin>>s;
if(s[0]=='s')
{
scanf("%d%d%d",&p,&q,&r);
if(t%2==0) a.insert(a.begin()+p,juese(q,r));
else b.insert(b.begin()+p,juese(q,r));
}
else if(s[0]=='a')
{
scanf("%d%d",&p,&q);
if(t%2==0)
{
a[p].hp-=b[q].attack;
b[q].hp-=a[p].attack;
if(a[p].hp<=0)
{
if(p==0) flag=-1;
else a.erase(a.begin()+p);
}
if(b[q].hp<=0)
{
if(q==0) flag=1;
else b.erase(b.begin()+q);
}
}
else
{
b[p].hp-=a[q].attack;
a[q].hp-=b[p].attack;
if(a[q].hp<=0)
{
if(q==0) flag=-1;
else a.erase(a.begin()+q);
}
if(b[p].hp<=0)
{
if(p==0) flag=1;
else b.erase(b.begin()+p);
}
}
}
else if(s[0]=='e') t++;
}
printf("%d\n",flag);
printf("%d\n",a[0].hp);
printf("%d",a.size()-1);
for(int i=1;i<a.size();i++)
printf(" %d",a[i].hp);
printf("\n");
printf("%d\n",b[0].hp);
printf("%d",b.size()-1);
for(int i=1;i<b.size();i++)
printf(" %d",b[i].hp);
printf("\n");
return 0;
}