Py||Basketball game

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/Lhw_666/article/details/102754614

题目描述
The NBA has a comprehensive judgment index for the player’s technical statistics - the efficiency value, which is calculated as:

efficiency value = [(score + rebound + assists + steal + block) - (number of shots - number of hits) - (number of free throws - The number of successful free throws) - the number of turnovers,

now you need to write a program to calculate the player’s efficiency value based on the technical statistics string of the player’s single game. The technical statistics string contains various basketball game data, corresponding to the following:
1Y- one successful free throw and get 1 score
1N - one missed free throw without the score
2Y - one successful shooting with 2 scores
2N - one missed shooting without a score
3Y - one successful three-points shooting get 3 scores
3N- one missed three-points shooting without a score
R-rebound
A-assisted
S- steal
B- block
T-turnover
Note: The number of shots = 2Y+2N+3Y+3N, the score is calculated as: 1 point for a free throw, 2 points for a two-pointer, and 3 points for a three-pointer.

输入
The input includes multiple lines of data, each line represents a technical statistic string of a player’s single game, such as 1Y1N2Y2N3Y3NRASBT, indicating that the player has two “free throw” and one get score, has two “two 2-point shooting” and one get score, has two “three-point shooting” and one get score, and the player has 1 rebound, 1 assist, 1 steal, 1 block, 1 turnover, 4 shots.
Each line of technical statistics string does not contain other characters and does not exceed 1000 characters.

输出
For each line of input, output the player’s efficiency value, such as the efficiency value of 1Y1N2Y2N3Y3NRASBT is (6+1+1+1+1)-(4-2)-(2-1)-1=6

样例输入 Copy
1Y1N2Y2N3Y3NRASBT
1Y1Y
样例输出 Copy
6
2

while True:
    s=[]
    s=[str(i) for i in input()]
    flag=0
    num=num2=num3=num4=score=0
    for i in s:
        if i=='1':
            flag=1
            num=num+1
        if i=='2':
            flag=2
            num=num+1
        if i=='3':
            flag=3
            num=num+1
        if flag!=0:
            if i=='Y':
                score=score+flag
                num4=num4+1
                flag=0
        if i=='R':
            num2=num2+1
        if i=='A':
            num2=num2+1
        if i=='S':
            num2=num2+1
        if i=='B':
            num2=num2+1
        if i=='T':
            num3=num3+1
    print(score+num2-num+num4-num3)

猜你喜欢

转载自blog.csdn.net/Lhw_666/article/details/102754614
今日推荐