zoukankan      html  css  js  c++  java
  • ZOJ Problem Set – 2321 Filling Out the Team

    Time Limit: 2 Seconds      Memory Limit: 65536 KB

    Over the years, the people of the great city of Pittsburgh have repeatedly demonstrated a collective expertise at football second to none. Recently a spy has discovered the true source of the city's football power-a wizard known only as "Myron," who is infallible at selecting the proper position at which each player will excel.

    Now that you know the source of Pittsburgh's wisdom, you are determined to provide your school's football team with a computer program that matches the wisdom of "Myron." You have consulted with the best football minds you can find, and they have dispensed their wisdom on the slowest speed, minimum weight, and minimum strength required to play each position.

    Position

    Slow.Speed

    Min.Weight

    Min.Strength

    Wide Receiver

    4.5

    150

    200

    Lineman

    6.0

    300

    500

    Quarterback

    5.0

    200

    300

    Using this knowledge, you will develop a program that reads in several players physical attributes and outputs what position(s) they are able to play.

     

    Input

    Each line of the input file will list the attributes for one player:

    <speed> <weight> <strength>

    Each number will be a real-valued number. The file will end with a line reading "0 0 0".

     

    Output

    For each player, you will output one line listing the positions that player can play. A player can play a position if each of their attributes is greater or equal to the minimum for weight and strength, and less than or equal to the slowest speed. If a player can play multiple positions, output them in the order listed above, separated by whitespace. You can not leave an extra space at the end of the line. If a player can play no positions, write "No positions" on the line.

     

    Sample Input

    4.4 180 200
    5.5 350 700
    4.4 205 350
    5.2 210 500
    0 0 0

     

    Sample Output

    Wide Receiver
    Lineman
    Wide Receiver Quarterback
    No positions

    Source: Mid-Atlantic USA 2004

     

    #include<iostream>

    #include<map>

    #include<string>

     

    using namespace std;

     

    class Position

    {

    private:

        string name;

        double lowestSpeed;

        double minWeight;

        double minStrength;

    public:

        Position(){}

     

        string GetName()

        {

            return this->name;

        }

        Position(string name, double lowestSpeed, double minWeight, double minStrength)

        {

            this->name=name;

            this->lowestSpeed = lowestSpeed;

            this->minWeight = minWeight;

            this->minStrength = minStrength;

        }

     

        bool MathPosition(double speed, double weight, double strength)

        {

            return (weight >= this->minWeight && strength >= this->minStrength && speed <= this->lowestSpeed);

        }

    };

    int main()

    {

        Position **p = new Position*[3];

     

        *p = new Position("Wide Receiver", 4.5, 150, 200);

        *(p+1) = new Position("Lineman", 6.0, 300, 500);

        *(p+2) = new Position("Quarterback", 5.0, 200, 300);

     

        double s, w, str;

        while(cin>>s>>w>>str && (s != 0 || w != 0 || str != 0))

        {

            int matchCount = 0;

            if((*p)->MathPosition(s,w,str)){

                cout<<(*p)->GetName();

                matchCount++;

            }

            if((*(p+1))->MathPosition(s,w,str)){

                if(matchCount != 0)

                    cout<<" ";

                cout<<(*(p+1))->GetName();

                matchCount++;

            }

            if((*(p+2))->MathPosition(s,w,str)){

                if(matchCount != 0)

                    cout<<" ";

                cout<<(*(p+2))->GetName();

                matchCount++;

            }

            if(matchCount == 0)

                cout<<"No positions";

            cout<<endl;

        }

     

        

        delete[] p;

        p = NULL;

     

        return 0;

    }

  • 相关阅读:
    如何通过一行代码制作个人专属动态微信二维码?
    小白学 Python 数据分析(14):Pandas (十三)数据导出
    小白学 Python 数据分析(13):Pandas (十二)数据表拼接
    小白学 Python 数据分析(12):Pandas (十一)数据透视表(pivot_table)
    小白学 Python 数据分析(11):Pandas (十)数据分组
    小白学 Python 数据分析(10):Pandas (九)数据运算
    小白学 Python 数据分析(9):Pandas (八)数据预处理(2)
    小白学 Python 数据分析(8):Pandas (七)数据预处理
    小白学 Python 数据分析(7):Pandas (六)数据导入
    小白学 Python 数据分析(6):Pandas (五)基础操作(2)数据选择
  • 原文地址:https://www.cnblogs.com/malloc/p/3426864.html
Copyright © 2011-2022 走看看