poj 魔兽世界之二:装备
程序员文章站
2024-03-17 18:10:58
...
#include <iostream>
using namespace std;
int Hours = 0;
string arm[] = { "sword", "bomb", "arrow" };
class Dragon {
public:
float morale;//怒气
int weapon;
static int strength;
};
class Ninja {
public:
int weapon1;
int weapon2;
static int strength;
};
class Iceman {
public:
int weapon;
static int strength;
};
class Lion {
public:
int loyalty;//忠诚度
static int strength;
};
class Wolf {
public:
static int strength;
};
class Headquarter {
int nDragon;
int nNinja;
int nIceman;
int nLion;
int nWolf;
int i;
int idNumber;
public:
int M;//生命源
string name;//司令部名
Headquarter(int v1 = 0, int v2 = 0, int v3 = 0, int v4 = 0, int v5 = 0, int v6 = 0, int v7 = 1) :nDragon(v1), nNinja(v2), nIceman(v3), nLion(v4), nWolf(v5), i(v6) , idNumber(v7){}
void born(int worriors[]) {
while (i < 5) {
if (worriors[i] == 0 && M >= Dragon::strength) {
Dragon dragon;
M -= Dragon::strength;
dragon.weapon = idNumber % 3;
dragon.morale = (float)M / Dragon::strength;
nDragon++;
printf("%03d %s %s %d born with strength %d,%d %s in %s headquarter\n", Hours, name.data(), "dragon", idNumber, Dragon::strength, nDragon, "dragon", name.data());
printf("It has a %s,and it's morale is %.2f\n", arm[dragon.weapon].data(), dragon.morale);
idNumber++;
i++;
break;
}
if (worriors[i] == 1 && M >= Ninja::strength) {
Ninja ninja;
M -= Ninja::strength;
ninja.weapon1 = idNumber % 3;
ninja.weapon2 = (idNumber + 1) % 3;
nNinja++;
printf("%03d %s %s %d born with strength %d,%d %s in %s headquarter\n", Hours, name.data(), "ninja", idNumber, Ninja::strength, nNinja, "ninja", name.data());
printf("It has a %s and a %s\n", arm[ninja.weapon1].data(), arm[ninja.weapon2].data());
idNumber++;
i++;
break;
}
if (worriors[i] == 2 && M >= Iceman::strength) {
Iceman iceman;
M -= Iceman::strength;
iceman.weapon = idNumber % 3;
nIceman++;
printf("%03d %s %s %d born with strength %d,%d %s in %s headquarter\n", Hours, name.data(), "iceman", idNumber, Iceman::strength, nIceman, "iceman", name.data());
printf("It has a %s\n", arm[iceman.weapon].data());
idNumber++;
i++;
break;
}
if (worriors[i] == 3 && M >= Lion::strength) {
Lion lion;
M -= Lion::strength;
lion.loyalty = M;
nLion++;
printf("%03d %s %s %d born with strength %d,%d %s in %s headquarter\n", Hours, name.data(), "lion", idNumber, Lion::strength, nLion, "lion", name.data());
printf("It's loyalty is %d\n", lion.loyalty);
idNumber++;
i++;
break;
}
if (worriors[i] == 4 && M >= Wolf::strength) {
nWolf++;
printf("%03d %s %s %d born with strength %d,%d %s in %s headquarter\n", Hours, name.data(), "wolf", idNumber, Wolf::strength, nWolf, "wolf", name.data());
M -= Wolf::strength;
idNumber++;
i++;
break;
}
i++; if (i == 5) i = 0;
}
if (i == 5) i = 0;
}
void stop() {
printf("%03d %s headquarter stops making warriors\n", Hours, name.data());
}
};
int Dragon::strength = 0;
int Ninja::strength = 0;
int Iceman::strength = 0;
int Lion::strength = 0;
int Wolf::strength = 0;
int main() {
int n, m, r[5] = { 2, 3, 4, 1, 0 }, b[5] = { 3, 0, 1, 2, 4 }, min;//n为数据组数,m为生命元,红军出兵顺序,蓝军出兵顺序
cin >> n;
int i = 1;
while (n > 0) {
cin >> m;
cin >> Dragon::strength >> Ninja::strength >> Iceman::strength >> Lion::strength >> Wolf::strength;//输入五种兵类的初始生命值
int strength[5] = { Dragon::strength, Ninja::strength, Iceman::strength, Lion::strength, Wolf::strength };
min = strength[0];
for (int k = 1; k < 5; k++) {//求出最小生命值
if (strength[k] < min)min = strength[k];
}
Headquarter Red, Blue;//建造司令营
Red.name = "red";
Red.M = m;
Blue.M = m;
Blue.name = "blue";
int flagRs = 0, flagBs = 0;
cout << "Case:" << i << endl;
while (1) {
if (Red.M >= min) {
Red.born(r);
}
else if (flagRs == 0) {
Red.stop();
flagRs = 1;
}
if (Blue.M >= min) {
Blue.born(b);
}
else if (flagBs == 0) {
Blue.stop();
flagBs = 1;
}
if (flagBs && flagRs) break;
Hours++;
}
Hours = 0;
i++;
n--;
}
return 0;
}
上一篇: jQuery基础(一)
下一篇: MySQL DDL 操作实践