-
前引
我现在心里非常非常开心:)
经过了中午下午两午的战斗,我终于Accept 了
经历了无数次的对比out.txt
终于 的 终 于
AC !
-
他人思路鸣谢
-
我的代码(已AC
#include<iostream>
#include<iomanip>
#include<string>
using namespace std;
#define Max 10
//dragon 、ninja、iceman、lion、wolf//是所有的顺序 除造兵顺序外
//简洁,有类特性的ac 为了ac
char allweapon[3][6]={"sword","bomb","arrow"};
char allname[5][Max]={"dragon","ninja","iceman","lion","wolf"};
int order [2][5]={{2,3,4,1,0},{3,0,1,2,4}};//红方蓝方造兵顺序
int Next[2];
class wolf;
class dragon;
class lion;
class iceman;
class ninja;
//class dragon :public soldier
wolf* pwolf[2][100]={NULL};
lion* plion[2][100]={NULL};
dragon* pdragon[2][100]={NULL};
iceman* piceman[2][100]={NULL};
ninja* pninja[2][100]={NULL};
class headquarter{//是公有,还是写友元? 还是写get函数
public:
headquarter(bool insquare,int inlife)
{
square=insquare;
life=inlife;
NOAS=0;
}
bool square;
int life;
int NOAS;
int nos[5]={0};
bool givebirth(int (&slife)[5]);
int cirr=0;
bool fu=true;
//iceman、lion、wolf、ninja、dragon红方顺序
//lion、dragon、ninja、iceman、wolf 蓝方顺序
//dragon 、ninja、iceman、lion、wolf//是所有的顺序 除造兵顺序外
private:
};
class soldier
{
public:
soldier(int inlife,int namenum)//构造函数确定数据
{
life=inlife;
name=allname[namenum];
}
private:
char* name;
int life;
};
class iceman :public soldier
{
public://传入基地指针可以吗?取决于headquarter类 //而何时调用headquarter类还需要构造
iceman(int inlife,headquarter& temp):soldier(inlife,2)//构造函数确定继承类特定数据
{
temp.life=temp.life-inlife;
weapon1=allweapon[temp.NOAS%3];
cout<<"It has a "<<weapon1<<endl;
}
private:
char* weapon1;
};
class dragon :public soldier
{
public:
dragon(int inlife,headquarter& temp):soldier(inlife,0)//inlife传入通过一个数组,固有属性存在数组
{
weapon1=allweapon[temp.NOAS%3];
temp.life=temp.life-inlife;
loyalty=temp.life*1.0/inlife;
cout<<"It has a "<<weapon1<<",and it's morale is "<<fixed<< setprecision(2)<<loyalty<<endl;
}
private:
char* weapon1;
double loyalty;
};
class ninja :public soldier
{
public:
ninja(int inlife,headquarter& temp):soldier(inlife,1)
{
temp.life=temp.life-inlife;
weapon1=allweapon[temp.NOAS%3];
weapon2=allweapon[(temp.NOAS+1)%3];
cout<<"It has a "<<weapon1<<" and a "<<weapon2<<endl;
}
private:
char* weapon1;
char* weapon2;
};
class lion :public soldier
{
public:
lion(int inlife,headquarter& temp):soldier(inlife,3)
{
temp.life=temp.life-inlife;
loyalty=temp.life;//造成功再减生命值? 不 先判定 判定好即可
cout<<"It's loyalty is "<<loyalty<<endl;
}
private:
int loyalty;//lion的忠诚度与dragon的不同?int or double
};
class wolf :public soldier
{
public:
wolf(int inlife,headquarter& temp):soldier(inlife,4)
{
temp.life=temp.life-inlife;
}
};
bool headquarter::givebirth(int (&slife)[5])
{
if(fu==true)
{
Next[square]=0;
fu=false;
}
for(int i=1;;)
{
string fang;
if(square==0)
{
fang="red";
}
if(square==1)
{
fang="blue";
}
if(life>=slife[order[square][Next[square]%5]])
{
nos[order[square][Next[square]%5]]++;
NOAS++;
cout<<setw(3)<<setfill('0')<<cirr<<' '<<fang<<' '<<allname[order[square][Next[square]%5]];
cout<<" "<<NOAS<<" ";
cout<<"born with strength "<<slife[order[square][Next[square]%5]];
cout<<','<<nos[order[square][Next[square]%5]]<<" "<<allname[order[square][Next[square]%5]];
cout<<" in "<<fang<<" headquarter"<<endl;
if(order[square][Next[square]%5]==0)
{
pdragon[square][nos[0]]=new dragon(slife[0],*this);
}
if(order[square][Next[square]%5]==1)
{
pninja[square][nos[1]]=new ninja(slife[1],*this);
}
if(order[square][Next[square]%5]==2)
{
piceman[square][nos[2]]=new iceman(slife[2],*this);
}
if(order[square][Next[square]%5]==3)
{
plion[square][nos[3]]=new lion(slife[3],*this);
}
if(order[square][Next[square]%5]==4)
{
pwolf[square][nos[4]]=new wolf(slife[4],*this);
}
Next[square]++;
cirr++;
return true;
}
if(i==6)
{
cout<<setw(3)<<setfill('0')<<cirr<<" "<<fang<<" "<<"headquarter stops making warriors"<<endl;
this->cirr++;//跟输出//构造在一块,输出一个东西后++;
return false;
}
else
{
i++;
Next[square]++;
}
}
//this->cirr++;//跟输出//构造在一块,输出一个东西后++;
}
int main ()
{
//初始化
int endtime;//游戏次数
cin>>endtime;
int headlife;
int slife[5];
int yy=1;
while(endtime--)
{
Next[0]=Next[1]=0;
cin>>headlife;
for(int i=0;i<=4;i++)
{
cin>>slife[i];
}
headquarter red(0,headlife),blue(1,headlife);
bool end=true,end1=true,end2=true;
cout<<"Case:"<<yy<<endl;
while(end)
{
if(end1)
end1=red.givebirth(slife);//不能生产返回false
if(end2)
end2=blue.givebirth(slife);
if(!end1&&!end2)
{
end=false;
}
}
yy++;
}
return 0;
}
/*
1
20
3 4 5 6 7
1
400
20 3 300 60 98
--------------------------------
Process exited after 13.15 seconds with return value 0
请按任意键继续. . .
*/
-
结果
坚持,耐住性子就是胜利
快乐AC每一天