【得分排行】
/* 得分排行 */ #include<stdio.h> #include<stdlib.h> #define MAX 100 #define MIN 0 int main(void) { int score[MAX + 1] = {0}; int juni[MAX + 2] = {0}; int count = 0, i; printf("输入分数, -1 结束:"); do { scanf("%d", &score[count++]); }while(score[count - 1] != -1); count--; for(i = 0; i < count; i++) { juni[score[i]]++; } juni[MAX + 1] = 1; for(i = MAX; i >= MIN; i--) { juni[i] = juni[i] + juni[i + 1]; } printf("得分\t排行\n"); for(i = 0; i < count; i++) { printf("%d\t%d\n", score[i], juni[score[i] + 1]); } return 0; }
运行结果:
转载本博请联系作者! 如有问题请在评论区评论或者发邮件:@libras