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]);