本文共 1329 字,大约阅读时间需要 4 分钟。
#include #include #include #include #include #include #include using namespace std;int n;string cmd;int now=0;struct node{ int attack; int health; node(int _attack,int _health):attack(_attack),health(_health){}};vector smn[2];vector ::iterator it;void init(){ for(int i=0;i<2;i++){ smn[i].clear(); smn[i].push_back(node(0,30)); } now=0;}void summon(){ int position,attack,health; cin>>position>>attack>>health; it=smn[now].begin(); smn[now].insert(it+position,node(attack,health));}void attack(){ int attacker,defender; cin>>attacker>>defender; smn[now][attacker].health-=smn[now^1][defender].attack; smn[now^1][defender].health-=smn[now][attacker].attack; for(int i=0;i<2;i++){ for(it=smn[i].begin()+1;it 0){ printf("-1\n"); }else if(smn[0][0].health>0&&smn[1][0].health>0){ printf("0\n"); }else{ printf("1\n"); } for(int i=0;i<2;i++){ printf("%d\n",smn[i][0].health); printf("%d",(int)smn[i].size()-1); for(int j=1;j<(int)smn[i].size();j++){ printf(" %d ",smn[i][j].health); } printf("\n"); }}int main(){ init(); cin>>n; while(n--){ cin>>cmd; if(cmd=="summon"){ summon(); }else if(cmd=="attack"){ attack(); }else if(cmd=="end"){ now^=1; } } end(); return 0;}
转载于:https://www.cnblogs.com/itcsl/p/9215292.html