005:魔兽世界之一:备战

这是一个特别的寒假,疫情来临,寒假延迟,想着之前学C#有诸多疑问,便循着源头学起了C/C++,mooc北大郭炜老师的程序设计课,万万没想到,课上内容看似简单,出的测试题确实让我头大,光是一个005:魔兽世界之一:备战,就让我花了一天的时间。怎么说呢,面向对象设计程序的思想还不到位,只能硬着头皮写。诸多小bug耽搁了许多时间,终于还是写出来了。还是得多动手才行呀。与君共勉。

#include <iostream>
#include <algorithm>
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;
}

几乎没怎么应用类,用的都是比较朴实的方法,错误多发于判断表达式是不是少了个等号,或者数字是否出错。总而言之,还是成功了!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值