005:魔兽世界之一:备战

#include<iostream>
#include<iomanip> 
#include<cstring>
using namespace std;
static int TIME=0;
class Creature;
void f1(int,Creature * &,int,int,int,int,int);
int Min(int n1,int n2, int n3,int n4,int n5)
{
    
    
 int temp=n1;
 if(n2<temp)
  temp=n2;
 if(n3<temp)
  temp=n3;
 if(n4<temp)
  temp=n4;
 if(n5<temp)
  temp=n5;
 return temp;
}
class Creature
{
    
    
protected:
 int strength;
 int num;
public:
 char name[10];
 Creature * next;
 virtual Creature* produce(int &,char*,int);
};
Creature * Creature::produce(int &_m,char * _name,int bianhao)
{
    
    
 if(_m>=strength)
 {
    
    
  num++;
  _m-=strength;
  cout<<setw(3)<<setfill('0')<<TIME<<" "<<_name<<" "<<name<<" "<<bianhao<<" born with strength "<<strength<<","<<num<<" "<<name<<" in "<<_name<<" headquarter"<<endl;
  return next;
 }
 else
 {
    
    
  return next->produce(_m,_name,bianhao);
 }
 
}
class Dragon:public Creature
{
    
    
public:
 Dragon(int);
};
Dragon::Dragon(int _strength)
{
    
    
 num=0;
 strength=_strength;
 strcpy(name,"dragon");
 
}
class Iceman:public Creature
{
    
    
public:
 Iceman(int);
 ~Iceman();
};
Iceman::Iceman(int _strength)
{
    
    
 num=0;
 strength=_strength;
 strcpy(name,"iceman");
}
class Ninja:public Creature
{
    
    
public:
 Ninja(int);
};
Ninja::Ninja(int _strength)
{
    
    
 num=0;
 strength=_strength;
 strcpy(name,"ninja");
}
class Wolf:public Creature
{
    
    
public:
 Wolf(int);
};
Wolf::Wolf(int _strength)
{
    
    
 num=0;
 strength=_strength;
 strcpy(name,"wolf");
}
class Lion:public Creature
{
    
    
public:
 Lion(int);
};
Lion::Lion(int _strength)
{
    
    
 num=0;
 strength=_strength;
 strcpy(name,"lion");
}
class Headquarter
{
    
    
 int M;
 Creature * p[5];
 Creature * now;
 int min;
 char name[10];
 int bianhao;
public:
 Headquarter(int,int,int,int,int,int,int,int,int,int,int,int,const char *);
 ~Headquarter();
 void Produce(bool &);
};
Headquarter::Headquarter(int _M,int _d,int _n,int _i,int _l,int _w,int no1,int no2,int no3,int no4,int no5,int _min,const char * _name)
{
    
    
 M=_M;
 f1(no1,p[0],_d,_n,_i,_l,_w);
 f1(no2,p[1],_d,_n,_i,_l,_w);
 f1(no3,p[2],_d,_n,_i,_l,_w);
 f1(no4,p[3],_d,_n,_i,_l,_w);
 f1(no5,p[4],_d,_n,_i,_l,_w);
 p[0]->next=p[1];
 p[1]->next=p[2];
 p[2]->next=p[3];
 p[3]->next=p[4];
 p[4]->next=p[0];
 min=_min;
 now=p[0];
 strcpy(name,_name);
 bianhao=0;
}
Headquarter::~Headquarter()
{
    
    
 for(int i=0;i<5;i++)
 {
    
    
  delete p[i];
 }
}
void Headquarter::Produce(bool &flag)
{
    
    
 if(min<=M)
 {
    
    
  bianhao++;
  now=now->produce(M,name,bianhao);
 }
 else
 {
    
    
  flag=0;
  cout<<setw(3)<<setfill('0')<<TIME<<" "<<name<<" headquarter stops making warriors"<<endl;
 }
}
void f1(int no,Creature * &p,int _d,int _n,int _i,int _l,int _w)
{
    
    
 switch(no)
 {
    
    
  case 'D':
   p=new Dragon(_d);
   break;
  case 'N':
   p=new Ninja(_n);
   break;
  case 'I':
   p=new Iceman(_i);
   break;
  case 'L':
   p=new Lion(_l);
   break;
  case 'W':
   p=new Wolf(_w);
   break;
 }
}
int main()
{
    
    
 int n;
 cin>>n;
 for(int u=0;u<n;u++)
 {
    
    
  TIME=0;
  int M,d,n,i,l,w;
  cin>>M>>d>>n>>i>>l>>w;
  cout<<"Case:"<<u+1<<endl;
  int min=Min(d,n,i,l,w);
  Headquarter red(M,d,n,i,l,w,'I','L','W','N','D',min,"red");
  Headquarter blue(M,d,n,i,l,w,'L','D','N','I','W',min,"blue");
  bool flagred,flagblue;
  if(M>=min)
  {
    
    
   flagred=1;
   flagblue=1;
  }
  else
  {
    
    
   flagred=0;
   flagblue=0;
   red.Produce(flagred);
   blue.Produce(flagblue);
  }
  while(flagred==1||flagblue==1)
  {
    
    
   if(flagred==1)
   {
    
    
    red.Produce(flagred);
   }
   if(flagblue==1)
   {
    
    
    blue.Produce(flagblue);
   }
   TIME++;
  }
 }
 return 0;
}

猜你喜欢

转载自blog.csdn.net/Warmmm/article/details/104443021
今日推荐