2021-03-27 17:46

# 魔兽世界第一阶段：备战代码哪里错了，一直WA

#include<iostream>
#include<iomanip>
#include<cstring>
using namespace std;
string soldiernames[5]={"dragon","ninga","iceman","lion","wolf"};
int redorder[5]={2,3,4,1,0};
int blueorder[5]={3,0,1,2,4};
public:
int alllife;
int colourjudge;
int num;
int soldiernum[5];
string soldiername[5];
int soldierlife[5];
headquarter(int life, int colour, const int order[], const int lifenum[])
{
num=0;
alllife=life;
colourjudge=colour;
for(int i=0; i<5; i++)
{
soldiernum[i]=0;
soldiername[i]=soldiernames[order[i]];
soldierlife[i]=lifenum[order[i]];
}
}
void soldierproducts(int time, int cnt)
{
num++;
soldiernum[cnt]++;
cout << setfill('0') << setw(3) << time << " " << headquartername << " " << soldiername[cnt]
<< " " << num << " born with strength " << soldierlife[cnt] << "," << soldiernum[cnt]
<< " " << soldiername[cnt] << " in " << headquartername << " headquarter" << endl;
alllife -= soldierlife[cnt];

}
bool stopproduct()
{
bool flag=1;
for(int i=0; i<5; i++)
{
if(alllife >= soldierlife[i])
{
flag=0;
}
}
return flag;
}
};

int main()
{
int t=0;
cin>>t;
int l=0;
while(l<t)
{
l++;
int flag1=0,flag2=0;
int cnt1=0,cnt2=0;
int m;
cin>>m;
int lifenum[5]={0};
for(int i=0; i<5; i++)
cin>>lifenum[i];
cout << "Case:" << l << endl;
for(int time=0; (!flag1||!flag2); time++)
{
if(flag1==0)
{
if(red.stopproduct())
{
cout << setfill('0') << setw(3) << time << " red headquarter stops making warriors" << endl;
flag1=1;
}
else
{
while(1)
{
if(red.alllife>=red.soldierlife[cnt1])
{
red.soldierproducts(time,cnt1);
if(cnt1==4)
cnt1=0;
else
cnt1++;
break;
}
else
{
if(cnt1==4)
cnt1=0;
else
cnt1++;
}
}
}
}

if(flag2==0)
{
if(blue.stopproduct())
{
cout << setfill('0') << setw(3) << time << " blue headquarter stops making warriors" << endl;
flag2=1;
}
else
{
while(1)
{
if(blue.alllife>=blue.soldierlife[cnt2])
{
blue.soldierproducts(time,cnt2);
if(cnt2==4)
cnt2=0;
else
cnt2++;
break;
}
else
{
if(cnt2==4)
cnt2=0;
else
cnt2++;
}
}
}
}
}

}
return 0;
}

1) 武士降生

2) 司令部停止制造武士

```1
20
3 4 5 6 7
```

```Case:1
000 red iceman 1 born with strength 5,1 iceman in red headquarter
000 blue lion 1 born with strength 6,1 lion in blue headquarter
001 red lion 2 born with strength 6,1 lion in red headquarter
001 blue dragon 2 born with strength 3,1 dragon in blue headquarter
002 red wolf 3 born with strength 7,1 wolf in red headquarter
002 blue ninja 3 born with strength 4,1 ninja in blue headquarter
003 red headquarter stops making warriors
003 blue iceman 4 born with strength 5,1 iceman in blue headquarter
004 blue headquarter stops making warriors```
• 点赞
• 写回答
• 关注问题
• 收藏
• 邀请回答

#### 1条回答默认 最新

• 有问必答小助手 2021-03-29 18:55

你好，我是问答小助手，本次您提出的有问必答问题，技术专家团超时未为您做出解答

本次提问扣除的有问必答次数，将会以问答VIP体验卡（1次有问必答机会、商城购买实体图书享受95折优惠）的形式为您补发到账户。

​​​​​因为有问必答VIP体验卡有效期仅有1天，您在需要使用的时候【私信】联系我，我会为您补发。

点赞 评论