Dev C++和CLion上能过,输出与题目要求一致,可是poj提示WA,大家帮忙找找原因。
#include <iostream>
#include <string>
#include <string.h>
using namespace std;
const int WARRIOR_NUM = 5;
const int SPACE_NUM = 10;
class Headquarter{
public:
int total_hp;
int color;
string colorName[SPACE_NUM];
string names[SPACE_NUM];
int warrior_num[SPACE_NUM];
int produce_seq[SPACE_NUM];
int hp[SPACE_NUM];
public:
void Init(int, int, const int *, const int*);
int Produce(int);
};
void Headquarter::Init(int color_, int thp, const int * ini_hp, const int* seq) {
color = color_;
total_hp = thp;
memcpy(hp, ini_hp, SPACE_NUM * sizeof(int));
memcpy(produce_seq, seq, SPACE_NUM * sizeof(int));
for(int i=0;i<WARRIOR_NUM;i++)
warrior_num[i]=0;
colorName[0] = "red",colorName[1] = "blue";
names[0] = "dragon",names[1] = "ninja",names[2] = "iceman",names[3] = "lion",names[4] = "wolf";
}
int Headquarter::Produce(int t) {
int no = t % WARRIOR_NUM;
int warrior_id = produce_seq[no];
if(total_hp - hp[warrior_id] >= 0)
{
total_hp -= hp[warrior_id];
warrior_num[warrior_id]++;
printf("%03d %s %s %d born with strength %d,%d %s in %s headquarter\n",
t,colorName[color].c_str(),names[warrior_id].c_str(),t+1,hp[warrior_id],
warrior_num[warrior_id],names[warrior_id].c_str(),colorName[color].c_str());
return 1;
}
else
{
no++;
while(no != t % WARRIOR_NUM)
{
int new_id = produce_seq[no];
if(total_hp - hp[new_id] >= 0)
{
total_hp -= hp[new_id];
warrior_num[new_id]++;
printf("%03d %s %s %d born with strength %d,%d %s in %s headquarter\n",
t,colorName[color].c_str(),names[new_id].c_str(),t+1,hp[new_id],
warrior_num[new_id],names[new_id].c_str(),colorName[color].c_str());
return 1;
}
else{no = (no+1)%WARRIOR_NUM;}
}
printf("%03d %s headquarter stops making warriors\n",t,colorName[color].c_str());
return 0;
}
}
int main()
{
int test_num;
int ini_hp[SPACE_NUM];
int tNum = 1;
Headquarter RedHead, BlueHead;
int redSeq[SPACE_NUM] = {2, 3, 4, 1, 0};
int blueSeq[SPACE_NUM] = {3, 0, 1, 2, 4};
cin>>test_num;
while(tNum<=test_num)
{
int t = 0;
int stop_sign = 1;
printf("Case:%d\n", tNum);
int thp;
cin>>thp;
for( int i = 0;i < WARRIOR_NUM;i++)
cin>>ini_hp[i];
RedHead.Init(0,thp,ini_hp,redSeq);
BlueHead.Init(1,thp,ini_hp,blueSeq);
int s1=1,s2=1;
while(stop_sign)
{
if(s1)
s1 = RedHead.Produce(t);
if(s2)
s2 = BlueHead.Produce(t);
t++;
if(s1==0 && s2==0) stop_sign = 0;
}
tNum++;
}
return 0;
}