1 #include <bits/stdc++.h> 2 using namespace std; 3 int dragon=0,ninja=0,iceman=0,lion=0,wolf=0; 4 int N; 5 int life; 6 class HQ{ 7 public: 8 char * color; 9 int working=1; 10 int life; 11 int cp=0; //目前造到哪一个小兵,SEQUENCE中的下标 12 int sub=1; // 小兵的下标 13 14 char* na[5]={"dragon","ninja","iceman","lion","wolf"}; //小兵名字 15 char* we[3]={"sword","bomb","arrow"}; 16 int sequence[5]; //造兵顺序 17 int con[5]; //造每个兵的消耗 18 int num[5]={0,0,0,0,0}; //每种小兵的数量 19 20 HQ(int a[5],char *c){ 21 memcpy(sequence,a,5*sizeof(int)); 22 color=new char[10]; 23 strcpy(color,c); 24 } 25 void init(int a,int b,int c,int d,int e){ 26 con[0]=a;con[1]=b;con[2]=c;con[3]=d;con[4]=e; 27 } 28 void reset(){ 29 working=1; 30 for(int i=0;i<5;i++) 31 num[i]=0; 32 cp=0; 33 sub=1; 34 } 35 36 void stop(){ 37 if(!working){ 38 cout<<color<<" headquarter stops making warriors"<<endl; 39 } 40 } 41 void weapon(){ 42 if(sequence[cp]==4) 43 return; 44 else if(sequence[cp]==3){ 45 cout<<"It's loyalty is "<<life<<endl; 46 return; 47 } 48 else if(sequence[cp]==0){ 49 cout<<"It has a "<<we[sub%3]<<",and it's morale is "; 50 printf("%.2f ",(float)life/con[sequence[cp]]); 51 return; 52 } 53 else if(sequence[cp]==1) { 54 cout << "It has a " << we[sub % 3] << " and a "<< we[(sub + 1) % 3]<<endl; 55 return; 56 } 57 else if(sequence[cp]==2){ 58 cout<<"It has a "<<we[sub%3]<<endl; 59 } 60 61 } 62 void making(){ 63 if(!working) 64 return; 65 int j; 66 for(j=1;j<=5;j++){ 67 if(life>=con[sequence[cp]]){ 68 num[sequence[cp]]++; 69 cout<<color<<" "<<na[sequence[cp]]<<" "<<sub<<" "<<"born with strength "<<con[sequence[cp]]; 70 cout<<','<<num[sequence[cp]]<<' '<<na[sequence[cp]]<<" in "<<color<<" headquarter"<<endl; 71 life-=con[sequence[cp]]; 72 weapon(); 73 74 cp=(cp+1)%5; 75 sub++; 76 break; 77 } 78 cp=(cp+1)%5; 79 80 } 81 if(j==6){ 82 working=0; 83 stop(); 84 } 85 } 86 }; 87 88 89 90 int main() { 91 int a[5]={2,3,4,1,0}; 92 int b[5]={3,0,1,2,4}; 93 HQ red(a,"red"),blue(b,"blue"); 94 95 cin>>N; 96 for(int i=1;i<=N;i++){ 97 red.reset(); 98 blue.reset(); 99 cin>>life; 100 red.life=life; 101 blue.life=life; 102 103 cin>>dragon>>ninja>>iceman>>lion>>wolf; 104 red.init(dragon,ninja,iceman,lion,wolf); 105 blue.init(dragon,ninja,iceman,lion,wolf); 106 107 cout<<"Case:"<<i<<endl; 108 for(int j=0;;j++){ 109 if(red.working){ 110 printf("%03d ",j); 111 red.making(); 112 } 113 if(blue.working){ 114 printf("%03d ",j); 115 blue.making(); 116 } 117 118 119 if(!red.working&&!blue.working) 120 break; 121 } 122 } 123 return 0; 124 }
好像还挺好玩的??