"C ++ Programming POJ" "WEEK3 advanced classes and objects," "World of Warcraft one of the programming work: preparing for"

https://www.cnblogs.com/dagon/p/4750100.html

Source: POJ  (Coursera Disclaimer: POJ exercises done on the final score will not count towards the Coursera.)

Note: The total time limit: 1000ms Memory Limit: 65536kB

description

World of Warcraft is west of the Red Devils army headquarters, east of the Blue Devils army headquarters. Between the two is the headquarters of a number of cities in order of priority.

Red Command, City 1, City 2, ......, City n, blue Command

Military headquarters will manufacture warrior. There are a warrior dragon, ninja, iceman, lion, wolf are five. Each warrior has a number, the value of life, attack power of these three attributes.

The two sides are calculated from the number of warriors start 1. Red square created by the n-th warrior, number is n. Similarly, the blue side created by the n-th warrior, number is n.

Samurai has a value of life when just born.

In each hour, each in command of both a warrior born.

Order red side command iceman, lion, wolf, ninja, dragon warrior manufacturing cycle.

Command blue side in order lion, dragon, ninja, iceman, wolf warrior manufacturing cycle.

Manufacturing warrior need the element of life.

Producing an initial value m warrior life, the life of the command element is necessary to reduce the m.

If the headquarters of the element of life is not sufficient to manufacture a warrior in the order should be made, then it is trying to build the next command. If all warriors can not be created, the headquarters of cease manufacture warrior.

Given a time, and the number of initial headquarters of both the element of life, requires you to start from 0:00 to command both sides to stop all events until the warrior manufacturing output in sequence.

There are two events, the corresponding sample output is as follows:

1) born warrior

Sample output: 004 blue lion 5 born with strength 5,2 lion in red headquarter

It represents 4 o'clock, No. 5 Blue Devils lion warrior born, the birth of life when it is 5, after the birth of the Blue Devils headquarters in a total of two lion warrior. (For simplicity, regardless of the plural form of a word) Note that each create a new warrior, output at this time how many have this kind of samurai headquarters in total.

2) Command to stop the manufacture warrior

Sample output: 010 red headquarter stops making warriors

Represents the whole, the red side to stop manufacturing headquarters at 10:00 warrior

Output events:

First output in chronological order;

The incident occurred at the same time, the output of the first Red Command, the headquarters of the blue and then output.

 

Entry

The first row is an integer representing the number of the test data set.

Each test were two rows.

The first line: an integer M. Its meaning, each of the M command has a start element of life (1 <= M <= 10000).

The second line: five integer, followed by dragon, the initial value of life ninja, iceman, lion, wolf's. They are greater than 0 and less than equal to 10,000.

 

Export

For each test, the required output from the 0:00 start, to the headquarters of the two sides have stopped manufacturing all events until the samurai.

For each test, first outputs "Case: n" n is the number of test data, from the beginning.

Next, the output of all events in the proper order and format. Each event at the time the event occurred at the beginning of the time in hours, three.

 

Sample input

1
20
3 4 5 6 7

 

Sample Output

Case:1
000 red iceman 1 born with strength 5,1 iceman in red headquarter
000 blue lion 1 born with strength 6,1 lion in blue headquarter
001 red lion 2 born with strength 6,1 lion in red headquarter
001 blue dragon 2 born with strength 3,1 dragon in blue headquarter
002 red wolf 3 born with strength 7,1 wolf in red headquarter
002 blue ninja 3 born with strength 4,1 ninja in blue headquarter
003 red headquarter stops making warriors
003 blue iceman 4 born with strength 5,1 iceman in blue headquarter
004 blue headquarter stops making warriors

#include <the iostream> 
#include <The iomanip> 
#include < String >
 the using  namespace STD; 

class Headquarters 
{ 
Private :
     int lifeValue;
     int redOrBlue; // red headquarters is 0, the value of the blue headquarters. 1 
    int COUNT; // production the number of soldiers 
    int warriorCounts [ 5 ]; // record the number of soldiers in each array 
    String headquarterName; // name of the headquarters of the 
    String warriorNames [ 5 ];   // record the name of each soldier an array of 
    intwarriorValues [ 5 ]; // array of records each life value of soldiers 
public : 
    Headquarters ( const  int theLifeValue, const  int theRedOrBlue,
         const  int theWarriorValue [],
         const  String theWarriorNames [],
         const  int the Order [],
         const  String theHeadquarterNames [] );
     ~ Headquarters () {};
     // Get the value of life, for comparing the minimum values of the life of the soldiers at the main program, and a comparison of the value of the soldiers life 
    int getLifeValue () { return lifeValue;} 

    // Get be health-born soldiers
    int getWarriorValue(int position)
    {
        return warriorValues[position];
    }
    void product(int time, int position);

};
/*指定初始化*/
headquarters::headquarters(const int theLifeValue, const int theRedOrBlue,
    const int theWarriorValue[],
    const string theWarriorNames[],
    const int order[],
    const string theHeadquarterNames[])
{
    count = 0 ; 
    lifeValue = theLifeValue; 
    redOrBlue = theRedOrBlue; 
    headquarterName = theHeadquarterNames [redOrBlue]; // obtain the array name from headquarters headquarters name 
    for ( int I = 0 ; I < . 5 ; ++ I) 
    { 
        warriorCounts [I] = 0 ;
         // the array in a given order and the name of the original soldiers, the headquarters to give the soldier array name 
        warriorNames [I] = theWarriorNames [order [I]];
         // a given order and given the name of the original array of soldiers to give the soldier health headquarters array 
        warriorValues [I] = theWarriorValue [Order [I]];
    } 

} 
/ * Production warrior 
time parameters for a given round-born soldier 
position parameters for a given position in the headquarters of the warrior born soldier in 
* / 
void Headquarters :: Product ( int time, int position) 
{ 
    COUNT ++ ; 
    warriorCounts [position ] ++; // total number of species plus one soldier
     // output requirements of the subject statement 
    COUT << setfill ( ' 0 ' ) << setw ( . 3 ) Time << << "  " << << headquarterName "  " < < 
        warriorNames [position] << "  " << count << " born with strength " <<
        warriorValues[position] << "," << warriorCounts[position] <<
        " " << warriorNames[position] << " in " << headquarterName << " headquater" <<
        endl;
    lifeValue -= warriorValues[position];

}
int main()
{
    const int redOrder[5] = { 2,3,4,1,0 };constsend troops to the headquarters of the order of red//
     int blueOrder [ . 5 ] = { . 3 , 0 , . 1 , 2 , . 4 }; // troops order blue headquarters 
    const  String headquartersNames [ 2 ] = { " Red " , " Blue " }; // record the name of the array Headquarters 
    
    // record the name of the array warrior 
    const  String priorNames [ . 5 ] = { " Dragon " , " Ninja " , " Iceman " , " Lion","wolf" };

    int n = 0;
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        int priorValue[5], headquartersValue, minValue, redPosition = 0,
            bluePosition = 0;
        bool redHadStop = false;
        bool blueHadStop = false;
        cin >> headquartersValue; // Get the value of life Headquarters
         // Get the value of the life of each soldier 
        for ( int J = 0 ; J < . 5 ; J ++ ) 
        { 
            CIN >> priorValue [J]; 
        } 
        COUT << " Case: " << << I endl; 

        // calculate the minimum value of life soldiers in 
        the minValue priorValue = [ 0 ];
         for ( int J = . 1 ; J < . 5 ; J ++ ) 
        { 
            IF (priorValue [J] < the minValue)
            { 
                The minValue  =priorValue [J]; 
            } 
        } 
        // initialize Red and blue Headquarters Headquarters 
        Headquarters RedOne = Headquarters (headquartersValue, 0 , priorValue, priorNames, redOrder, headquartersNames); 
        Headquarters blueOne = Headquarters (headquartersValue, . 1 , priorValue, priorNames, blueOrder , headquartersNames);
         for ( int Time = 0 ;! redHadStop || blueHadStop;! Time ++ ) 
        { 
            // if did not stop the Red Army troops, continued 
            IF ! ( redHadStop) 
            { 
                //Red life of less than the minimum value of life soldiers, troops stopped, the print command 
                IF (redOne.getLifeValue () <the minValue) 
                { 
                    COUT << setfill ( ' 0 ' ) << setw ( . 3 ) << << Time " Red Headquarter stops Making Warriors " << endl; 
                    redHadStop = to true ; 
                } 
                the else 
                { 
                    // the filter is determined from the above sentences now will be able to send troops.
                    // from the current position began to increase, to a position to send troops to stop 
                    the while ( to true ) 
                    { 
                        IF (redOne.getLifeValue ()> = redOne.getWarriorValue (redPosition))
                        {
                            redOne.product(time, redPosition);
                            if (redPosition == 4 ? redPosition = 0 : redPosition++);
                            break;
                        }
                        else
                        {
                            if (redPosition == 4 ? redPosition = 0 : redPosition++);
                        }
                    }
                }
            }
            if (!blueHadStop)
            {
                if (blueOne.getLifeValue() < minValue)
                {
                    cout << setfill('0') << setw(3) << time << " blue uarter stops making warriors" << endl;
                    blueHadStop = true;

                }
                else {
                    while (true)
                    {
                        if (blueOne.getLifeValue() >= blueOne.getWarriorValue(bluePosition))
                        {
                            blueOne.product(time, bluePosition);
                            if (bluePosition == 4 ? bluePosition = 0 : bluePosition++);
                            break;
                        }
                        else
                        {
                            if (bluePosition == 4 ? bluePosition = 0 : bluePosition++);
                        }

                    }
                }
            }
        }
    }
    while (1);
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/focus-z/p/10994238.html