问题描述

魔兽世界的西面是红魔军的司令部,东面是蓝魔军的司令部。两个司令部之间是依次排列的若干城市。

红司令部,City 1,City 2,……,City n,蓝司令部

两军的司令部都会制造武士。武士一共有 dragon 、ninja、iceman、lion、wolf 五种。每种武士都有编号、生命值这两种属性。

有的武士可以拥有武器。武器有三种,sword, bomb,和arrow,编号分别为0,1,2。

双方的武士编号都是从1开始计算。红方制造出来的第 n 个武士,编号就是n。同样,蓝方制造出来的第 n 个武士,编号也是n。

不同的武士有不同的特点。

dragon 可以拥有一件武器。编号为n的dragon降生时即获得编号为 n%3 的武器。dragon还有“士气”这个属性,是个浮点数,其值为它降生后其司令部剩余生命元的数量除以造dragon所需的生命元数量。

ninjia可以拥有两件武器。编号为n的ninjia降生时即获得编号为 n%3 和 (n+1)%3的武器。

iceman有一件武器。编号为n的iceman降生时即获得编号为 n%3 的武器。

lion 有“忠诚度”这个属性,其值等于它降生后其司令部剩余生命元的数目。

wolf没特点。

请注意,在以后的题目里,武士的士气,生命值,忠诚度在其生存期间都可能发生变化,都有作用,武士手中的武器随着使用攻击力也会发生变化。

武士在刚降生的时候有一个生命值。

在每个整点,双方的司令部中各有一个武士降生。

红方司令部按照 iceman、lion、wolf、ninja、dragon 的顺序循环制造武士。

蓝方司令部按照 lion、dragon、ninja、iceman、wolf 的顺序循环制造武士。

制造武士需要生命元。

制造一个初始生命值为 m 的武士,司令部中的生命元就要减少 m 个。

如果司令部中的生命元不足以制造某个按顺序应该制造的武士,那么司令部就试图制造下一个。如果所有武士都不能制造了,则司令部停止制造武士。

给定一个时间,和双方司令部的初始生命元数目,要求你将从0点0分开始到双方司令部停止制造武士为止的所有事件按顺序输出。

一共有两种事件,其对应的输出样例如下:

1) 武士降生

输出样例: 004 blue lion 5 born with strength 5,2 lion in red headquarter

表示在 4点整,编号为5的蓝魔lion武士降生,它降生时生命值为5,降生后蓝魔司令部里共有2个lion武士。(为简单起见,不考虑单词的复数形式)注意,每制造出一个新的武士,都要输出此时司令部里共有多少个该种武士。

如果造出的是dragon,那么还要输出一行,例:

It has a arrow,and it’s morale is 23.34

表示该dragon降生时得到了arrow,其士气是23.34(为简单起见,本题中arrow前面的冠词用a,不用an,士气精确到小数点后面2位,四舍五入)

如果造出的是ninjia,那么还要输出一行,例:

It has a bomb and a arrow

表示该ninjia降生时得到了bomb和arrow。

如果造出的是iceman,那么还要输出一行,例:

It has a sword

表示该iceman降生时得到了sword。

如果造出的是lion,那么还要输出一行,例:

It’s loyalty is 24

表示该lion降生时的忠诚度是24。

2) 司令部停止制造武士

输出样例: 010 red headquarter stops making warriors

表示在 10点整,红方司令部停止制造武士

输出事件时:

首先按时间顺序输出;

同一时间发生的事件,先输出红司令部的,再输出蓝司令部的。

输入

第一行是一个整数,代表测试数据组数。

每组测试数据共两行。

第一行,一个整数M。其含义为: 每个司令部一开始都有M个生命元( 1 <= M <= 10000)

第二行:五个整数,依次是 dragon 、ninja、iceman、lion、wolf 的初始生命值。它们都大于0小于等于10000

输出

对每组测试数据,要求输出从0时0分开始,到双方司令部都停止制造武士为止的所有事件。

对每组测试数据,首先输出“Case:n” n是测试数据的编号,从1开始

接下来按恰当的顺序和格式输出所有事件。每个事件都以事件发生的时间开头,时间以小时为单位,有三位。

样例输入

1
20
3 4 5 6 7

样例输出

Case:1
000 red iceman 1 born with strength 5,1 iceman in red headquarter
It has a bomb
000 blue lion 1 born with strength 6,1 lion in blue headquarter
It's loyalty is 14
001 red lion 2 born with strength 6,1 lion in red headquarter
It's loyalty is 9
001 blue dragon 2 born with strength 3,1 dragon in blue headquarter
It has a arrow,and it's morale is 3.67
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
It has a sword and a bomb
003 red headquarter stops making warriors
003 blue iceman 4 born with strength 5,1 iceman in blue headquarter
It has a bomb
004 blue headquarter stops making warriors

提示
屏蔽的代码部分是想写一个数组来记录每一个产生的士兵信息,调试过程中老是内存泄漏,就先去掉了,以后再改。
源码

#include <iostream>
#include <iomanip>
#include <string>
using namespace std;class warrior
{
protected:int id;int lifeValue;//士兵生命值string name;
public:static string weaponNames[3];warrior():id(-1), lifeValue(0), name("") {}warrior(int theId, int theLifeValue, string theName):id(theId), lifeValue(theLifeValue), name(theName) {}~warrior(){}int getId() {return id;}string* getWeaponNames() {return weaponNames;}virtual void print(const int times, const string campName, const int certainWarriorCounts) {};//纯虚函数
};
string warrior::weaponNames[3] = {"sword", "bomb", "arrow"};
class dragon : public warrior
{
private:float morale;//士气属性
public:dragon(int theId, int theLifeValue, int headquarterLifeValue):warrior(theId, theLifeValue, "dragon"){morale = (float)headquarterLifeValue / theLifeValue;}~dragon() {}float getMorale() {return morale;}string getWeaponName() {int index = this->getId() % 3;return this->getWeaponNames()[index];}void print(const int times, const string campName, const int certainWarriorCounts){cout << setfill('0') << setw(3) << times << " " << campName << " " << this->name<< " " << this->id << " born with strength " << this->lifeValue << "," << certainWarriorCounts<< " " << this->name << " in " << campName << " headquarter" << endl;cout << "It has a " << this->getWeaponName() << ",and it's morale is " << setprecision(2) << fixed <<this->getMorale() << endl;}
};
class ninja : public warrior
{
private:
public:ninja(int theId, int theLifeValue) : warrior(theId, theLifeValue, "ninja") {}~ninja() {}string getFirstWeaponName(){int index = this->getId() % 3;return this->getWeaponNames()[index];}string getSecondWeaponName(){int index = (this->getId() + 1) % 3;return this->getWeaponNames()[index];}void print(const int times, const string campName, const int certainWarriorCounts){cout << setfill('0') << setw(3) << times << " " << campName << " " << this->name<< " " << this->id << " born with strength " << this->lifeValue << "," << certainWarriorCounts<< " " << this->name << " in " << campName << " headquarter" << endl;cout << "It has a " << this->getFirstWeaponName() << " and a " << this->getSecondWeaponName() << endl;}
};
class iceman : public warrior
{public:iceman(int theId, int theLifeValue) : warrior(theId, theLifeValue, "iceman") {}~iceman() {}string getWeaponName(){int index = this->getId() % 3;return this->getWeaponNames()[index];}void print(const int times, const string campName, const int certainWarriorCounts){cout << setfill('0') << setw(3) << times << " " << campName << " " << this->name<< " " << this->id << " born with strength " << this->lifeValue << "," << certainWarriorCounts<< " " << this->name << " in " << campName << " headquarter" << endl;cout << "It has a " << this->getWeaponName() << endl;}
};class lion : public warrior
{
private:int loyalty;
public:lion(int theId, int theLifeValue, int headquarterLifeValue) : warrior(theId, theLifeValue, "lion"){loyalty = headquarterLifeValue;}~lion() {}int getLoyalty() {return loyalty;}void print(const int times, const string campName, const int certainWarriorCounts){cout << setfill('0') << setw(3) << times << " " << campName << " " << this->name<< " " << this->id << " born with strength " << this->lifeValue << "," << certainWarriorCounts<< " " << this->name << " in " << campName << " headquarter" << endl;cout << "It's loyalty is " << this->getLoyalty() << endl;}
};class wolf : public warrior
{
public:wolf(int theId, int theLifeValue) : warrior(theId, theLifeValue, "wolf") {}~wolf() {}void print(const int times, const string campName, const int certainWarriorCounts){cout << setfill('0') << setw(3) << times << " " << campName << " " << this->name<< " " << this->id << " born with strength " << this->lifeValue << "," << certainWarriorCounts<< " " << this->name << " in " << campName << " headquarter" << endl;}
};
class militarycamp
{
private:string name;int lifeValue;//部落生命值int counts;//士兵数量
//  int ptrsize;
//  warrior* ptr;//指向动态分配的武士的数组int currentPosition;//记录产生战士类别的当前位置int minWarriorValue;//计算出战士中的最小生命值  int warriorValues[5];//记录每种战士生命值的数组string warriorNames[5];//记录每种战士名字的数组int warriorCounts[5];//记录每种战士数量的数组
public:static string priorNames[5];//记录战士名字的数组static int times;//产生战士的次数bool hadStop;//是否停止出兵militarycamp(const int theLifeValue, string theName, const int theWarriorValue[],const int theWarriorOrder[]);~militarycamp() {
/*if(ptr) {delete[] ptr;}
*/}void push_back(warrior* w);void warriorManufacture();//制造武士
};
string militarycamp::priorNames[5] = {"dragon", "ninja", "iceman" ,"lion" ,"wolf"};
int militarycamp::times = 0;
militarycamp::militarycamp(const int theLifeValue, string theName, const int theWarriorValue[],const int theWarriorOrder[]):hadStop(false),currentPosition(0),counts(0),lifeValue(theLifeValue),name(theName)//,ptr(NULL),ptrsize(0)
{for (int i = 0; i < 5; i++){warriorCounts[i] = 0;warriorNames[i] = priorNames[theWarriorOrder[i]];//由给定的顺序和原始战士名字的数组,得到该总部战士名字的数组warriorValues[i] = theWarriorValue[theWarriorOrder[i]];//由给定的顺序和原始战士名字的数组,得到该总部战士生命值的数组}minWarriorValue = warriorValues[0];for (int i = 1; i < 5; i++){if (warriorValues[i] < minWarriorValue){minWarriorValue = warriorValues[i];}}
}
/*
制造武士
*/
void militarycamp::warriorManufacture()
{//生命值小于最小战士生命值,停止出兵,打印命令if (lifeValue < minWarriorValue){cout << setfill('0') << setw(3) << times << ' ' << name << " headquarter stops making warriors" << endl;hadStop = true;}else{//从上面的判断句筛选后,现在一定能出兵//从当前position开始增加,到某个位置出兵了停止while(true){if (lifeValue >= warriorValues[currentPosition]){counts++;warriorCounts[currentPosition]++;lifeValue -= warriorValues[currentPosition];if (warriorNames[currentPosition] == "dragon"){dragon theDragon(counts, warriorValues[currentPosition], lifeValue);
//                  push_back(&theDragon);theDragon.print(times, name, warriorCounts[currentPosition]);} else if(warriorNames[currentPosition] == "ninja"){ninja theNinja(counts, warriorValues[currentPosition]);
//                  push_back(&theNinja);theNinja.print(times, name, warriorCounts[currentPosition]);}else if (warriorNames[currentPosition] == "iceman"){iceman theIceman(counts, warriorValues[currentPosition]);
//                  push_back(&theIceman);theIceman.print(times, name, warriorCounts[currentPosition]);}else if (warriorNames[currentPosition] == "lion"){lion theLion(counts, warriorValues[currentPosition], lifeValue);
//                  push_back(&theLion);theLion.print(times, name, warriorCounts[currentPosition]);}else if (warriorNames[currentPosition] == "wolf"){wolf theWolf(counts, warriorValues[currentPosition]);
//                  push_back(&theWolf);theWolf.print(times, name, warriorCounts[currentPosition]);}           currentPosition == 4 ? currentPosition = 0 : currentPosition++;break;} else{currentPosition == 4 ? currentPosition = 0 : currentPosition++;}}}
}
/*
//加上此部分发生内存泄漏问题,尚未解决
void militarycamp::push_back(warrior* w)//在数组尾部添加一个元素
{if (ptr){warrior* tmpPtr = new warrior[ptrsize+1];//重新分配空间memcpy(tmpPtr, ptr, sizeof(warrior)*(ptrsize));delete[] ptr;ptr = tmpPtr;}else//数组本来就是空的{ptr = new warrior[1];}ptr[ptrsize++] = *w;//加入新的数组元素}
*/
int main()
{const int redOrder[5] = {2, 3, 4, 1, 0};//红色总部的出兵顺序const int blueOrder[5] = {3, 0, 1, 2, 4};//蓝色总部的出兵顺序int n = 0;//测试数cin >> n;for (int i = 1; i <= n; i++){int priorValue[5], headquartersValue;cin >> headquartersValue; //获取总部生命值//获取每种战士的生命值for (int j = 0; j < 5; j++){cin >> priorValue[j];}cout << "Case:" << i << endl;       //初始化红军总部和蓝军总部militarycamp redOne = militarycamp(headquartersValue, "red", priorValue, redOrder);militarycamp blueOne = militarycamp(headquartersValue, "blue", priorValue, blueOrder);militarycamp::times = 0;//派兵次数置零while(!redOne.hadStop || !blueOne.hadStop){if (!redOne.hadStop){redOne.warriorManufacture();}if (!blueOne.hadStop){blueOne.warriorManufacture();}militarycamp::times++;}}return 0;
}

魔兽世界之二:装备(C++程序设计第5周)相关推荐

  1. 魔兽世界终极版(C++程序设计第6周)

    问题描述 魔兽世界的西面是红魔军的司令部,东面是蓝魔军的司令部.两个司令部之间是依次排列的若干城市,城市从西向东依次编号为1,2,3 -. N ( N <= 20 ).红魔军的司令部算作编号为0 ...

  2. POJ C++程序设计 编程题#2 魔兽世界之二:装备

    编程题#2: 魔兽世界之二:装备 来源: POJ (Coursera声明:在POJ上完成的习题将不会计入Coursera的最后成绩.) 注意: 总时间限制: 1000ms 内存限制: 65536kB ...

  3. C++ 程序设计 week5 魔兽世界二: 装备

    编程题#2: 魔兽世界之二:装备 来源: POJ (Coursera声明:在POJ上完成的习题将不会计入Coursera的最后成绩.) 注意: 总时间限制: 1000ms 内存限制: 65536kB ...

  4. C++面向对象程序设计 021:魔兽世界之二:装备 ---- (北大Mooc)

    文章目录 专题博客链接 前引 他人博客优秀代码 我的代码(提交过不了 但是数据本地测试正常 一行一行的进行了对比 都不知道为什么AC不了) 闲聊 专题博客链接 北大C++ POJ课后习题博客全解记录 ...

  5. 北大C++课后题系列:022:魔兽世界之二:装备

    C++ 022:魔兽世界之二:装备 北大程序设计与算法(三) 描述 魔兽世界的西面是红魔军的司令部,东面是蓝魔军的司令部.两个司令部之间是依次排列的若干城市. 红司令部,City 1,City 2,- ...

  6. 开源项目 OpenJudge-3:魔兽世界之二:装备

    开源项目 OpenJudge-3:魔兽世界之二:装备 程序说明文档 Github地址 项目主要使用的技术: MVC模式.单例模式.继承与多态.虚函数.STL库.文件流.I/O流.字符串流.智能指针.g ...

  7. 程设作业:魔兽世界2:装备

    直接贴代码: #include <vector> #include <iostream> #include <iomanip> #include <strin ...

  8. 20175333曹雅坤 实验二 Java面向对象程序设计

    实验二 Java面向对象程序设计 实验内容 1. 初步掌握单元测试和TDD 2. 理解并掌握面向对象三要素:封装.继承.多态 3. 初步掌握UML建模 4. 熟悉S.O.L.I.D原则 5. 了解设计 ...

  9. python顺序结构实验设计_实验二 顺序结构程序设计(验证性实验)

    安徽工程大学 Python程序设计实验报告 班级物流192 姓名 徐敏 学号 3190505232 成绩 _____ 日期 2020.3.22 指导老师 修宇 [实验名称] 实验二 顺序结构程序设计( ...

  10. java面向对象实验结论及心得_20162305 实验二 Java面向对象程序设计 实验报告

    20162305 实验二 Java面向对象程序设计 实验报告 实验内容 1.初步掌握单元测试和TDD 2.理解并掌握面向对象三要素:封装.继承.多态 3.初步掌握UML建模 4.熟悉S.O.L.I.D ...

最新文章

  1. 没答好「进程间通信」,被面试官挂了....
  2. 014_哈希表内建函数
  3. 自定义值类型一定不要忘了重写Equals,否则性能和空间双双堪忧
  4. fmdb和mysql的区别_FMDB
  5. 漫画:五分钟看懂车联网
  6. 轻松解决Android gradle太慢问题
  7. 一元线性回归多元线性回归
  8. Centos7:dubbo监控中心安装,配置和使用
  9. 以编程方式管理IIS
  10. Mac磁盘项目管理工具DiskCatalogMaker
  11. file上传代码 ios_自己动手写一个 iOS 网络请求库(四)——快速文件上传
  12. 黑客知识之7种DoS攻击方法简述
  13. D.Stressful Training--Educational Codeforces Round 61 (Rated for Div. 2)(二分+优先队列)
  14. grub4dos 启动ubuntu 12.04
  15. js判断当前浏览器的环境是微信、pc、还是手机端非微信环境
  16. 寒假的一点笔记《123速通》
  17. 小木虫为什么会有不好的用户体验?
  18. uni-app项目(首页)
  19. 高通平台开发系列讲解(USB篇)Composite USB gadget framework
  20. IE浏览器-官网下载地址

热门文章

  1. 为什么孩子对成人的话听而不闻?
  2. 同文输入法 android,Trime(同文输入法)app安卓最新版下载-Trime输入法下载 - 欧普软件园...
  3. 解析护照OCR识别/护照识别
  4. ExecuteSQL函数
  5. 奇异博士伯连对AI 区块连改造
  6. 怎么用Word制作三线表,这个方法收藏好
  7. 区块链系列(八)之区块链介绍
  8. 【Embedded System】嵌入式系统
  9. Python——计算方差、标准差、均方差、均方根值、均方误差、均方根误差
  10. 《A Survey on Deep Learning Technique for Video Segmentation》视频分割综述阅读笔记(翻译)