005:魔獣世界の一つ:準備

45625 ワード

これは特別な冬休みで、疫病が来て、冬休みが遅れて、前にCを勉強して多くの疑問があることを考えて、源に従ってC/C++、mooc北大郭炜先生のプログラム設計の授業を学んで、まさか、授業の内容は簡単に見えて、出したテスト問題は確かに私の頭を大きくして、005:魔獣の世界の1つです:準備戦、私に1日の時間を費やしました.なんというか、オブジェクト向けのプログラミングの思想がまだ不十分で、無理に書くしかありません.多くの小さなバグが多くの時間を費やして、ついに書いてしまった.やはりもっと手を出さなければなりませんね.君と共に励ます.
#include 
#include 
using namespace std;
class A
{
	public:
		int strb;
		int strr;//      
		int bsoldier[5];
		int rsoldier[5];
		int Tb;
		int Tr;//          
		int time;
		int min;
		int bb;
		int j;
		A(int str,int dragon,int ninja,int iceman,int lion,int wolf,int omin);
		void produce()
		{
			int a[10] ={1,1,1,1,1,1,1,1,1,1};		
			while(Tr==1||Tb==1) 
			{
				if(Tr == 1) 
				{
					if(strr>=min)
					{			
						while(rsoldier[bb]>strr)
						{
							bb++;
							if(bb==5) bb = 0;
						}
						switch(bb) 
						{
							case 0:
							if(time<10){cout<<"00"<<time;}
							else cout<<"0"<<time;
							cout<<" red iceman "<<time+1<<" born with strength "<<rsoldier[0]<<","<<a[0]<<" iceman in red headquarter"<<endl;
							strr-=rsoldier[0];a[0]++;break;
							
							case 1:
							if(time<10){cout<<"00"<<time;}
							else cout<<"0"<<time;
							cout<<" red lion "<<time+1<<" born with strength "<<rsoldier[1]<<","<<a[1]<<" lion in red headquarter"<<endl;
							strr-=rsoldier[1];a[1]++;break;
							
							case 2:
							if(time<10){cout<<"00"<<time;}
							else cout<<"0"<<time;
							cout<<" red wolf "<<time+1<<" born with strength "<<rsoldier[2]<<","<<a[2]<<" wolf in red headquarter"<<endl;
							strr-=rsoldier[2];a[2]++;break;
							
							case 3:
							if(time<10){cout<<"00"<<time;}
							else cout<<"0"<<time;
							cout<<" red ninja "<<time+1<<" born with strength "<<rsoldier[3]<<","<<a[3]<<" ninja in red headquarter"<<endl;
							strr-=rsoldier[3];a[3]++;break;
							
							case 4:
							if(time<10){cout<<"00"<<time;}
							else cout<<"0"<<time;
							cout<<" red dragon "<<time+1<<" born with strength "<<rsoldier[4]<<","<<a[4]<<" dragon in red headquarter"<<endl;
							strr-=rsoldier[4];a[4]++;break;
						}
					}
					else 
					{
						if(time<10){cout<<"00"<<time;}
						else cout<<"0"<<time;
						cout<<" red headquarter stops making warriors"<<endl;
						Tr = 0;	
					} 	
				}
				
				if(Tb == 1) 
				{
					if(strb>=min)
					{
						while(bsoldier[j]>strb){
							j++;
							if(j==5){
							j = 0;};
						}
						switch(j){
							case 0:
								if(time<10){cout<<"00"<<time;}
							else cout<<"0"<<time;
							cout<<" blue lion "<<time+1<<" born with strength "<<bsoldier[0]<<","<<a[5]<<" lion in blue headquarter"<<endl;
							strb-=bsoldier[0];a[5]++;break;
							case 1:
								if(time<10){cout<<"00"<<time;}
							else cout<<"0"<<time;
							cout<<" blue dragon "<<time+1<<" born with strength "<<bsoldier[1]<<","<<a[6]<<" dragon in blue headquarter"<<endl;
							strb-=bsoldier[1];a[6]++;break;
							case 2:
								if(time<10){cout<<"00"<<time;}
							else cout<<"0"<<time;
							cout<<" blue ninja "<<time+1<<" born with strength "<<bsoldier[2]<<","<<a[7]<<" ninja in blue headquarter"<<endl;
							strb-=bsoldier[2];a[7]++;break;
							case 3:
								if(time<10){cout<<"00"<<time;}
							else cout<<"0"<<time;
							cout<<" blue iceman "<<time+1<<" born with strength "<<bsoldier[3]<<","<<a[8]<<" iceman in blue headquarter"<<endl;
							strb-=bsoldier[3];a[8]++;break;
							case 4:
								if(time<10){cout<<"00"<<time;}
							else cout<<"0"<<time;
							cout<<" blue wolf "<<time+1<<" born with strength "<<bsoldier[4]<<","<<a[9]<<" wolf in blue headquarter"<<endl;
							strb-=bsoldier[4];a[9]++;break;
						}
					}
					else 
					{
						if(time<10){cout<<"00"<<time;}
							else cout<<"0"<<time;
						cout<<" blue headquarter stops making warriors"<<endl;
						Tb = 0;	
					} 	
				}	 
				bb++;
				j++;
				if(j==5){
					j = 0;
				};
				if(bb==5){
					bb=0 ;
				}			
				time++;
			}
			bb = 0;
			j = 0;
			time = 0;
			return;	
		};
};
A::A(int str,int dragon,int ninja,int iceman,int lion,int wolf,int omin):strb(str),strr(str)
		{
			bsoldier[0] = lion;
			bsoldier[1] = dragon;
			bsoldier[2] = ninja;
			bsoldier[3] = iceman;
			bsoldier[4] = wolf;
			rsoldier[0] = iceman;
			rsoldier[1] = lion;
			rsoldier[2] = wolf;
			rsoldier[3] = ninja;
			rsoldier[4] = dragon;
			Tb = 1;
			Tr = 1;
			bb = 0;
			j = 0;
			min = omin;
			time = 0;
		};
int main()
{
	int ofmin;
	int caseNumber = 1;
	int caseTotal;		
	cin>>caseTotal;
	int str[caseTotal];
	int ss[caseTotal][5];
	for(int j=0;j<caseTotal;j++)
	{
		cin>>str[j];
		for(int i=0;i<5;i++)
		{
			cin>>ss[j][i];
		}
	}
	for(int i=0;i<caseTotal;i++)
		{	
		ofmin = min(min(min(min(ss[i][0],ss[i][1]),ss[i][2]),ss[i][3]),ss[i][4]);
		A AA(str[i],ss[i][0],ss[i][1],ss[i][2],ss[i][3],ss[i][4],ofmin);
		cout<<"Case:"<<caseNumber++<<endl;
		AA.produce();
		}
	return 0;
}

クラスはほとんど適用されず、比較的地味な方法で行われており、式が等号が少なくなったかどうか、数字が間違っているかどうかを判断するのに誤りが多い.要するに、成功した!