Answer to Question #316957 in Python for Manish

Question #316957

Scoring

A group of people(P) are playing an online game. Their scores are stored in the order of their entry time in S. Each integer S[i] corresponds to the score of the person Pi.

For each person Pi you have to report the number of people who played after the person and scored less than the person.


Input

The first line contains a single integer N.

The second line contains N space-separated


Output

The output should contain N space-separated integers representing the number of people who played after the person and scored less than the person.


Explanation

Given S = 13 12 11 Score of P1 is 13. Score of P2 is 12. Score of P3 is 11.The number of people who played after P1 and scored less than 13 is 2(12, 11). The number of people who played after P2 and scored less than 12 is 1(11). The number of people who played after P3 and scored less than 11 is 0.The output is 2 1 0.


Sample Input 1

3

13 12 11

Sample Output 1

2 1 0

Sample Input 2

4

4 3 5 2

Sample Output 2

2 1 1 0


1
Expert's answer
2022-03-26T02:38:24-0400

These set of codes performs the program:

# Scoring
def less_scores(A:list, B:int):
    """Displaying scores in an online game"""
    s = [0 for i in range(B)]
    for i in range(B-1):
        for j in range(i+1, B):
            if A[i] > A[j]:
                s[i] += 1
    print(*s)


while True:
    try:
        B = int(input())
        A = list(map(int, input().split()))
        if len(A) != B:
            raise ValueError
    except ValueError:
        print('Incorrect input, please try again!')
        continue
    less_scores(A, B)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS