Score ranking algorithm

Source: Internet
Author: User


Question

Assume that a teacher enters the test score based on the student's seat number and wants to automatically display the ranking of student scores after the input. Of course, the scores may be the same.

Algorithm:

1. Visit the fractional array A1 to obtain the array A2 with each score

2. Add the A2 score array to the left to obtain the ranking corresponding to the final score.

 

Analysis

Assume that the score range of the scores to be ranked is 1-N. This score range will automatically generate N orders (0 is the last one)

When the number of people P (n) is greater than or equal to N, there must be the same score in the score sequence, and the same score enjoys the same rank

When the number of people P (n) <n, there must be a score in the score sequence that does not belong to anyone, and the score ranking is empty





// Effect: rank a random number from 1 to 20. // generate a score array for (I = 0; I <snum; I ++) score [I] = rand () % snum + 1; // Number of people who access the score array to obtain the corresponding score array for (I = 0; I <snum; I ++) rank [score [I] ++; // obtain the score ranking [score + 1] → [ranking] for (I = snum; I> = 0; I --) rank [I] = rank [I] + rank [I + 1]; printf ("score rank: \ n"); // output score ranking for (I = 0; I <snum; I ++) printf ("score = % 2D Rank = % d \ n", score [I], rank [score [I] + 1]);





Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.