魔兽世界之一:备战
#include<iostream>
using namespace std;
#pragma warning(disable:4996)
class CHeadQuarter;
class CWarrior {
private:
int No;
int KindNo;
CHeadQuarter* p;
public:
static const char* WarriorName[5];
static int strength[5];
CWarrior(int No_, int KindNo_, int strength_, CHeadQuarter* p_) :No(No_), KindNo(KindNo_),p(p_) {}
void PrintResult(int t);
};
class CHeadQuarter {
int color;
int strength;
int anWarriorNum[5];
int TotalNum = 0;
int CurMakIdx = 0;
CWarrior* p[10000];
bool Stopped = false;
public:
static int MakSeq[2][5];
friend class CWarrior;
CHeadQuarter(int color_, int strength_) :color(color_), strength(strength_){
for (auto& e : anWarriorNum)
e = 0;
}
~CHeadQuarter() {
for (int i = 0;i < TotalNum;i++)
delete p[i];
}
bool creat(int t);
const char* GetColor() {
return color ? "blue" : "red";
}
};
void CWarrior::PrintResult(int t) {
printf("%03d %s %s %d born with strength %d,%d %s in %s headquarter\n",
t, p->GetColor(), CWarrior::WarriorName[KindNo], No, CWarrior::strength[KindNo], p->anWarriorNum[KindNo], WarriorName[KindNo], p->GetColor());
}
bool CHeadQuarter::creat(int t) {
if (Stopped)
return false;
int timer = 0;
while (strength < CWarrior::strength[MakSeq[color][CurMakIdx]] && timer < 5) {
++timer;
CurMakIdx = (CurMakIdx + 1) % 5;
}
if (timer == 5) {
Stopped = true;
printf("%03d %s headquarter stops making warriors\n", t, GetColor());
return false;
}
int KindNo = MakSeq[color][CurMakIdx];
p[TotalNum] = new CWarrior(TotalNum+1, KindNo, CWarrior::strength[KindNo], this);
strength -= CWarrior::strength[KindNo];
anWarriorNum[KindNo]++;
p[TotalNum++]->PrintResult(t);
CurMakIdx = (CurMakIdx + 1) % 5;
return true;
}
const char* CWarrior::WarriorName[5] = { "dragon", "ninja", "iceman", "lion", "wolf" };
int CWarrior:: strength[5];
int CHeadQuarter::MakSeq[2][5] = { {2,3,4,1,0},{3,0,1,2,4} };
int main() {
//freopen("C:\\Users\\czh\\Desktop\\2.txt", "r", stdin);
int CaseNum;
scanf("%d", &CaseNum);
for (int i = 1;i <= CaseNum;++i) {
printf("Case:%d\n", i);
int m;
scanf("%d", &m);
for (int j = 0;j < 5;j++)
scanf("%d", &CWarrior::strength[j]);
CHeadQuarter r(0, m), b(1, m);
int t = 0;
while (1) {
bool r_test, b_test;
r_test = r.creat(t);
b_test = b.creat(t);
++t;
if (r_test==0 && b_test==0)
break;
}
}
}