/*###题4 描述:10个学生考完期末考试评卷完成后,A老师需要划出及格线,要求如下:
1.及格线是10的倍数;
2.保证至少有60%的学生及格;
3.如果所有的学生都高于60分,则及格线为60分
输入:输入10个整数,取值0~100
输出:输出及格线,10的倍数
示例
输入:61 51 49 30 20 10 70 80 90 99
输出:50
*/
#include <stdio.h>
void quick_sort(int R[], int low, int high);
int get_jige_level(void){
int i = 0;
int score[10] = {0};
int count = 0;
int jige_level = 0;
printf("please input scores of 10 students:\n");
for(i = 0; i < 10; i++) {
scanf("%d",&score[i]);
if (score[i] >= 60)
count++;
}
if (count == 10) {
jige_level = 60;
return jige_level;
}else {
quick_sort(score, 0, 9);
for (i = 0; i < 10; i++)
printf("score[%d] = %d\n", i, score[i]);
jige_level = (score[4] / 10 ) * 10;//取第五名学生的成绩作为及格线
return jige_level;
}
}
void quick_sort(int R[], int low, int high) {//对R[low]到R[high]的关键字进行升序排序
int temp;
int i = low, j = high;
if (low < high) {
temp = R[low];//temp为枢轴
while(i != j) {
while(j > i && R[j] >= temp) {
--j;
}
if (i < j) {
R[i] = R[j];
++i;
}
while(i < j && R[i] <= temp) {
++i;
}
if (i < j) {
R[j] = R[i];
--j;
}
}
R[i] = temp;//或者R[j] = temp;
quick_sort(R, low, i - 1);
quick_sort(R, i + 1, high);
}
}
int main(int argc, char *argv[]) {
int jige_level = get_jige_level();
printf("jige_level = %d\n",jige_level);
return 0;
}