在同一所大学其不同专业的按所招人数与基地分数录取过程代码举例c语言
时间: 2023-12-14 19:39:21 浏览: 32
以下是一个简单的按照招生人数与基地分数的录取过程的 C 语言代码示例:
```c
#include <stdio.h>
struct Student {
char name[50];
int baseScore;
int examScore;
};
int main() {
int numSeats, numApplicants;
printf("Enter the number of available seats: ");
scanf("%d", &numSeats);
printf("Enter the number of applicants: ");
scanf("%d", &numApplicants);
struct Student applicants[numApplicants];
for (int i = 0; i < numApplicants; i++) {
printf("\nEnter the name of applicant %d: ", i+1);
scanf("%s", applicants[i].name);
printf("Enter the base score of applicant %d: ", i+1);
scanf("%d", &applicants[i].baseScore);
printf("Enter the exam score of applicant %d: ", i+1);
scanf("%d", &applicants[i].examScore);
}
// Sort applicants by base score in descending order
for (int i = 0; i < numApplicants-1; i++) {
for (int j = 0; j < numApplicants-i-1; j++) {
if (applicants[j].baseScore < applicants[j+1].baseScore) {
struct Student temp = applicants[j];
applicants[j] = applicants[j+1];
applicants[j+1] = temp;
}
}
}
// Accept top candidates up to the number of available seats
printf("\nAccepted candidates:\n");
for (int i = 0; i < numApplicants && i < numSeats; i++) {
if (applicants[i].baseScore >= 80 && applicants[i].examScore >= 60) {
printf("- %s\n", applicants[i].name);
}
}
return 0;
}
```
这个程序中,我们首先输入可用的招生名额和申请人数。然后,我们使用结构体存储每个申请人的基础分数和考试分数。接下来,我们按照基础分数对申请人进行排序,以便在后面选择候选人时更容易。最后,我们选择基础分数高于80分且考试分数高于60分的前 numSeats 个候选人,并将其打印出来。