Click here to Skip to main content
15,902,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
You are given the marks of a class of n students represented in the form of an array in sorted (non- decreasing) order. Your task is to print n space separated
integers representing the ranks of the students.
- Rules to Calculate the Ranks
1. The students with highest marks is Rank 1.
2. If two students have the same marks then they have same rank.
3. Due to Rule 2 some ranks are skipped.
For example:
Input:
marks (1 = {4, 6, 7, 8, 9, 9, 9, 10, 10, 15)
Output:
ranks [] = {10, 9, 8, 7, 4, 4, 4, 2, 2, 1)

index in array - 0 1 2 3 4 5 6 7 8 9
marks - 4 6 7 8 9 9 9 10 10 15
ranks - 10 9 8 7 4 4 4 2 2 1

In the above example since students at index 7 & 8 have same marks thus they have same rank ('2' after the highest rank '1' given to student at index 9) and thus rank 3 is skipped after which student 6 directly gets rank '4'.
Similarly since student 4, 5, 6 have the same marks rank '5' & '6' are skipped.

Input format:
1 Take input of n the number of students.
2. Take input of n space separated integers in marks[ ].

Output format:
1. Print n space separated Integers representing the ranks[ ] of the students.

Constraints:
1. (2 s n s 10,000).
2. (0 s marks[i] s 10' where (0 s I 5 n-1)).

What I have tried:

please solve this problem. I'm not getting it
Posted
Updated 8-Apr-22 14:42pm

1 solution

We're not here to do your work for you.

If you've got a problem understanding the assignment, ask your teacher. That way, they know the problem has to be described better.

I have no idea what you're not understanding, but the not so clear part is if there is a tie between students scores, they get the same rank, but skip the number of ranks equal to the number of tied students. Like this:
Rank    Student Score
  1          10
  2           9
  2           9
  2           9
  5           8
  6           7
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900