C++ Object-Oriented Programming 021: World of Warcraft II: Equipment ---- (Peking University Mooc)


Advance

I feel very, very uncomfortable in my heart now: (
Because my local IDE has tested countless times and the results I get are compared with the results given by the system,
line by line, word by word,
I just don’t know where I went wrong and
tested one. It’s too young
and this version of mine obviously cannot be used for big homework.
I can’t pass this bad writing method . I was really angry. After I found out that most
of everyone was writing like this bad writing method, but my real AC can’t be used. pissed off


Excellent code for other people's blogs

De Lin Enbao's World of Warcraft 2: Equipped with
soy sauce bottle was registered World of Warcraft 2: Equipment


My code (I can't submit it, but the local test of the data is normal. I compare it line by line and I don't know why AC can't)

#include <iostream>
#include <string>
#include <string.h>
#include <iomanip>
#include <math.h>
using namespace std;

class Weapons
{
    
    
public:
    string name[3];
    Weapons()
    {
    
    
        name[0] = "sword",name[1] = "bomb",name[2] = "arrow";
    }

};



class RedTeam
{
    
    
private:
    int producelife,dragonlife,ninjalife,icemanlife,lionlife,wolflife;
    int numbers[5],producechoose;
    int time,totalnum;
    int lifes[5];
    string name[5];
    string bornout,teamout;
    string hasout,loyalout,moraleout;
    Weapons Weapon;
    int loyalty;
    float morale;
public:
    int Rflag;
    RedTeam(int life,int dragon,int ninja,int iceman,int lion,int wolf)
    {
    
    
        producelife = life,dragonlife = dragon,ninjalife = ninja,icemanlife = iceman,lionlife = lion,wolflife = wolf;
        lifes[0] = icemanlife,lifes[1] = lionlife,lifes[2] = wolflife,lifes[3] = ninjalife,lifes[4] = dragonlife;
        name[0] = "iceman",name[1] = "lion",name[2] = "wolf",name[3] = "ninja",name[4] = "dragon";
        producechoose = totalnum = Rflag = time = 0;
        memset(numbers,0,sizeof(numbers));
        bornout = " born with strength ",teamout = " in red headquarter",hasout = "It has a ",loyalout = "It's loyalty is ",moraleout = ",and it's morale is ";
        loyalty = morale = 0;
    }
    void ProducePrint()
    {
    
    
        int i,flag = 0;
        for(i=0;i<5;i++)
        {
    
    
            if(producelife >= lifes[producechoose])
            {
    
    
                producelife -= lifes[producechoose];
                numbers[producechoose]++;
                totalnum++;
                cout<<setw(3)<<setfill('0')<<time<<" red ";
                cout<<name[producechoose]<<' '<<totalnum<<bornout<<lifes[producechoose]<<',';
                cout<<numbers[producechoose]<<' '<<name[producechoose]<<teamout<<endl;
                flag = 1;

                if(!producechoose)  cout<<hasout<<Weapon.name[totalnum%3]<<endl;
                else if(producechoose == 1) cout<<loyalout<<producelife<<endl;
                else if(producechoose == 3) cout<<hasout<<Weapon.name[totalnum%3]<<" and a "<<Weapon.name[(totalnum+1)%3]<<endl;
                else if(producechoose == 4) cout<<hasout<<Weapon.name[totalnum%3]<<moraleout<<fixed<<setprecision(2)<<((float)producelife/lifes[producechoose])<<endl;

            }
            producechoose++;
            if(producechoose == 5)  producechoose = 0;
            if(flag)break;
        }
        if(flag)
            time++;
        if(!flag){
    
    
            Rflag = 1;
            cout<<setw(3)<<setfill('0')<<time<<' '<<"red headquarter stops making warriors"<<endl;
                }
    }
};

class BlueTeam{
    
    
private:
    int producelife,dragonlife,ninjalife,icemanlife,lionlife,wolflife;
    int numbers[5],producechoose;
    int time,totalnum;
    int lifes[5];
    string name[5];
    string bornout,teamout;
    string hasout,loyalout,moraleout;
    Weapons Weapon;
    int loyalty;
    float morale;
public:
    int Bflag;
    BlueTeam(int life,int dragon,int ninja,int iceman,int lion,int wolf)
    {
    
    
        producelife = life,dragonlife = dragon,ninjalife = ninja,icemanlife = iceman,lionlife = lion,wolflife = wolf;
        totalnum = producechoose = Bflag = time = 0;
        name[0] = "lion",name[1] = "dragon",name[2] = "ninja",name[3] = "iceman",name[4] = "wolf";
        memset(numbers,0,sizeof(numbers));
        lifes[0] = lionlife,lifes[1] = dragonlife,lifes[2] = ninjalife,lifes[3] = icemanlife,lifes[4] = wolflife;
        bornout = " born with strength ",teamout = " in red headquarter",hasout = "It has a ",loyalout = "It's loyalty is ",moraleout = ",and it's morale is ";
        loyalty = morale = 0;
    }
    void ProducePrint()
    {
    
    
        int i,flag = 0;
        for(i=0;i<5;i++)
        {
    
    
            if(producelife >= lifes[producechoose])
            {
    
    
                producelife -= lifes[producechoose];
                numbers[producechoose]++;
                totalnum++;
                cout<<setw(3)<<setfill('0')<<time<<" blue "<<name[producechoose]<<' '<<totalnum<<' '<<bornout<<lifes[producechoose]<<',';
                cout<<numbers[producechoose]<<' '<<name[producechoose]<<teamout<<endl;
                flag = 1;

                if(producechoose == 3)  cout<<hasout<<Weapon.name[totalnum%3]<<endl;
                else if(!producechoose) cout<<loyalout<<producelife<<endl;
                else if(producechoose == 2) cout<<hasout<<Weapon.name[totalnum%3]<<" and a "<<Weapon.name[(totalnum+1)%3]<<endl;
                else if(producechoose == 1) cout<<hasout<<Weapon.name[totalnum%3]<<moraleout<<fixed<<setprecision(2)<<((float)producelife/lifes[producechoose])<<endl;
            }
            producechoose++;
            if(producechoose == 5)  producechoose = 0;
            if(flag == 1)break;
        }
        if(flag)
            time++;
        if(!flag){
    
    
            Bflag = 1;
            cout<<setw(3)<<setfill('0')<<time<<" blue headquarter stops making warriors"<<endl;
        }
    }
};

int main()
{
    
    
    int testtimes,producelife,dragonlife,ninjalife,icemanlife,lionlife,wolflife,i;
    cin>>testtimes;
    for(i=1;i<=testtimes;i++)
    {
    
    
        cin>>producelife;
        cin>>dragonlife>>ninjalife>>icemanlife>>lionlife>>wolflife;
        RedTeam R(producelife,dragonlife,ninjalife,icemanlife,lionlife,wolflife);
        BlueTeam B(producelife,dragonlife,ninjalife,icemanlife,lionlife,wolflife);
        cout<<"Case:"<<i<<endl;
        while(!R.Rflag || !B.Bflag)
        {
    
    
            if(!R.Rflag)R.ProducePrint();
            if(!B.Bflag)B.ProducePrint();
        }
    }
    return 0;
}

Small talk

I haven’t eaten since 1pm now.
Sometimes it’s really irritating to do this kind of questions,
but I think I wrote my PTA data structure in Zhejiang University.
Sometimes I really struggled for 4-5 hours. It’s like this.
There is no way to do anything. There are always imperfections (sigh)

Insert picture description here

Guess you like

Origin blog.csdn.net/qq_37500516/article/details/114924940