mirror of
https://github.com/renbaoshuo/202401-programming-assignments.git
synced 2024-12-16 15:44:39 +00:00
【实践课外】15.结构体1
This commit is contained in:
parent
8fe20e8f88
commit
01c7825e24
11
【实践课外】15.结构体1/6-1 选队长.c
Normal file
11
【实践课外】15.结构体1/6-1 选队长.c
Normal file
@ -0,0 +1,11 @@
|
||||
void showCaptain(TeamMember team[], int n) {
|
||||
TeamMember res = team[0];
|
||||
|
||||
for (int i = 1; i < n; i++) {
|
||||
if (team[i].ability > res.ability) {
|
||||
res = team[i];
|
||||
}
|
||||
}
|
||||
|
||||
printf("%d %s %s %s %.2lf\n", res.id, res.lastname, res.firstname, res.sex, res.ability);
|
||||
}
|
60
【实践课外】15.结构体1/6-1 选队长.md
Normal file
60
【实践课外】15.结构体1/6-1 选队长.md
Normal file
@ -0,0 +1,60 @@
|
||||
# 6-1 选队长
|
||||
|
||||
小明最近喜欢玩一款新游戏。在该游戏中,需要组建队伍去完成任务以获取奖励。小明挑出了所有的队员(每个人能力不同),需要一个函数挑出队长(能力最强的队员)。
|
||||
|
||||
### 函数接口定义:
|
||||
```c
|
||||
void showCaptain(TeamMember team[], int n);
|
||||
```
|
||||
|
||||
参数说明:team中从下标0开始存放n个TeamMember,n>0。
|
||||
函数功能:找出队长并输出其各项信息
|
||||
|
||||
### 裁判测试程序样例:
|
||||
```c
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
#define NAME_LEN 100
|
||||
#define SEX_LEN 6
|
||||
typedef struct {
|
||||
int id;//身份证号码
|
||||
char lastname[NAME_LEN+1];//姓
|
||||
char firstname[NAME_LEN+1];//名
|
||||
char sex[SEX_LEN];//性别
|
||||
double ability;
|
||||
} TeamMember;
|
||||
|
||||
void showCaptain(TeamMember team[], int n);
|
||||
int main()
|
||||
{
|
||||
TeamMember *team;
|
||||
int n;
|
||||
int i;
|
||||
|
||||
scanf("%d",&n);
|
||||
team = (TeamMember *)malloc(n*sizeof(TeamMember));
|
||||
for(i=0;i<n;i++)
|
||||
{
|
||||
scanf("%d %s %s %s %lf",&team[i].id,team[i].lastname, team[i].firstname, team[i].sex, &team[i]. ability);
|
||||
}
|
||||
|
||||
showCaptain(team, n);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* 您提交的代码将放置在这里 */
|
||||
```
|
||||
|
||||
### 输入样例:
|
||||
```in
|
||||
3
|
||||
123456 zhang san male 100
|
||||
123457 li si female 200.5
|
||||
123458 wang ming male 159.1
|
||||
```
|
||||
|
||||
### 输出样例:
|
||||
```out
|
||||
123457 li si female 200.50
|
||||
```
|
18
【实践课外】15.结构体1/6-2 按等级统计学生成绩.c
Normal file
18
【实践课外】15.结构体1/6-2 按等级统计学生成绩.c
Normal file
@ -0,0 +1,18 @@
|
||||
int set_grade(struct student *p, int n) {
|
||||
int cnt = 0;
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
if (p[i].score >= 85) {
|
||||
p[i].grade = 'A';
|
||||
} else if (p[i].score >= 70) {
|
||||
p[i].grade = 'B';
|
||||
} else if (p[i].score >= 60) {
|
||||
p[i].grade = 'C';
|
||||
} else {
|
||||
p[i].grade = 'D';
|
||||
cnt++;
|
||||
}
|
||||
}
|
||||
|
||||
return cnt;
|
||||
}
|
84
【实践课外】15.结构体1/6-2 按等级统计学生成绩.md
Normal file
84
【实践课外】15.结构体1/6-2 按等级统计学生成绩.md
Normal file
@ -0,0 +1,84 @@
|
||||
# 6-2 按等级统计学生成绩
|
||||
|
||||
本题要求实现一个根据学生成绩设置其等级,并统计不及格人数的简单函数。
|
||||
|
||||
### 函数接口定义:
|
||||
```c++
|
||||
int set_grade( struct student *p, int n );
|
||||
```
|
||||
其中`p`是指向学生信息的结构体数组的指针,该结构体的定义为:
|
||||
```
|
||||
struct student{
|
||||
int num;
|
||||
char name[20];
|
||||
int score;
|
||||
char grade;
|
||||
};
|
||||
```
|
||||
|
||||
`n`是数组元素个数。学号`num`、姓名`name`和成绩`score`均是已经存储好的。`set_grade`函数需要根据学生的成绩`score`设置其等级`grade`。等级设置:85-100为A,70-84为B,60-69为C,0-59为D。同时,`set_grade`还需要返回不及格的人数。
|
||||
|
||||
### 裁判测试程序样例:
|
||||
```c++
|
||||
#include <stdio.h>
|
||||
#define MAXN 10
|
||||
|
||||
struct student{
|
||||
int num;
|
||||
char name[20];
|
||||
int score;
|
||||
char grade;
|
||||
};
|
||||
|
||||
int set_grade( struct student *p, int n );
|
||||
|
||||
int main()
|
||||
{ struct student stu[MAXN], *ptr;
|
||||
int n, i, count;
|
||||
|
||||
ptr = stu;
|
||||
scanf("%d\n", &n);
|
||||
for(i = 0; i < n; i++){
|
||||
scanf("%d%s%d", &stu[i].num, stu[i].name, &stu[i].score);
|
||||
}
|
||||
count = set_grade(ptr, n);
|
||||
printf("The count for failed (<60): %d\n", count);
|
||||
printf("The grades:\n");
|
||||
for(i = 0; i < n; i++)
|
||||
printf("%d %s %c\n", stu[i].num, stu[i].name, stu[i].grade);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* 你的代码将被嵌在这里 */
|
||||
```
|
||||
|
||||
### 输入样例:
|
||||
```in
|
||||
10
|
||||
31001 annie 85
|
||||
31002 bonny 75
|
||||
31003 carol 70
|
||||
31004 dan 84
|
||||
31005 susan 90
|
||||
31006 paul 69
|
||||
31007 pam 60
|
||||
31008 apple 50
|
||||
31009 nancy 100
|
||||
31010 bob 78
|
||||
```
|
||||
|
||||
### 输出样例:
|
||||
```out
|
||||
The count for failed (<60): 1
|
||||
The grades:
|
||||
31001 annie A
|
||||
31002 bonny B
|
||||
31003 carol B
|
||||
31004 dan B
|
||||
31005 susan A
|
||||
31006 paul C
|
||||
31007 pam C
|
||||
31008 apple D
|
||||
31009 nancy A
|
||||
31010 bob B
|
||||
```
|
16
【实践课外】15.结构体1/6-3 学生成绩比高低.c
Normal file
16
【实践课外】15.结构体1/6-3 学生成绩比高低.c
Normal file
@ -0,0 +1,16 @@
|
||||
int compareScore(const struct Student *s1, const struct Student *s2) {
|
||||
int sum1 = s1->C + s1->English,
|
||||
sum2 = s2->C + s2->English;
|
||||
|
||||
if (sum1 == sum2) {
|
||||
if (s1->C > s2->C) return 1;
|
||||
if (s1->C < s2->C) return -1;
|
||||
|
||||
if (s1->English > s2->English) return 1;
|
||||
if (s1->English < s2->English) return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
return sum1 > sum2 ? 1 : -1;
|
||||
}
|
77
【实践课外】15.结构体1/6-3 学生成绩比高低.md
Normal file
77
【实践课外】15.结构体1/6-3 学生成绩比高低.md
Normal file
@ -0,0 +1,77 @@
|
||||
# 6-3 学生成绩比高低
|
||||
|
||||
学生结构体定义如下:
|
||||
```
|
||||
struct Student{
|
||||
int sid;
|
||||
int C;
|
||||
int English;
|
||||
};
|
||||
```
|
||||
其中`sid`是学号,`C`是C语言课程成绩,`English`是英语课程成绩。学生的成绩按照这样的规则比较:<br>
|
||||
* 先比较两门课的总成绩,总成绩高的为优;
|
||||
* 若总成绩相同,再比较C语言成绩,C语言成绩高的为优;
|
||||
* 若C语言成绩也相同,则说明两名学生成绩相等。
|
||||
|
||||
编写函数实现成绩的比较。
|
||||
### 函数接口定义:
|
||||
```c
|
||||
int compareScore(const struct Student *s1, const struct Student *s2);
|
||||
```
|
||||
其中`s1`和`s2`是传入的参数,分别指向两名学生的结构体变量。函数返回值为`int`型,<br>
|
||||
* 若`s1`所指学生成绩优于`s2`所指学生,返回`1`;
|
||||
* 若`s2`所指学生成绩优于`s1`所指学生,返回`-1`;
|
||||
* 若两学生成绩相等,返回`0`。
|
||||
|
||||
### 裁判测试程序样例:
|
||||
```c
|
||||
/* 此测试程序仅为示例,实际的测试程序可能不同。
|
||||
注意:实际的测试程序可能有多组输入、进行多次比较,输入格式也有可能不同,
|
||||
因此不要针对测试程序样例编写代码,而应当编写符合题目要求的函数 */
|
||||
|
||||
#include <stdio.h>
|
||||
struct Student{
|
||||
int sid;
|
||||
int C;
|
||||
int English;
|
||||
};
|
||||
int compareScore(const struct Student *s1, const struct Student *s2);
|
||||
int main(){
|
||||
struct Student zs, ls;
|
||||
scanf("%d%d%d", &zs.sid, &zs.C, &zs.English);
|
||||
scanf("%d%d%d", &ls.sid, &ls.C, &ls.English);
|
||||
int r;
|
||||
r = compareScore(&zs, &ls);
|
||||
if(r < 0) printf("Less\n");
|
||||
else if(r > 0) printf("Greater\n");
|
||||
else printf("Equal\n");
|
||||
return 0;
|
||||
}
|
||||
/* 你所编写的函数代码将被嵌在这里 */
|
||||
```
|
||||
|
||||
### 输入样例1:
|
||||
对于样例测试程序的输入格式:
|
||||
```in
|
||||
1 95 90
|
||||
2 90 91
|
||||
```
|
||||
|
||||
### 输出样例1:
|
||||
对于样例测试程序的输出格式:
|
||||
```out
|
||||
Greater
|
||||
```
|
||||
|
||||
### 输入样例2:
|
||||
对于样例测试程序的输入格式:
|
||||
```in
|
||||
1 90 95
|
||||
2 95 90
|
||||
```
|
||||
|
||||
### 输出样例2:
|
||||
对于样例测试程序的输出格式:
|
||||
```out
|
||||
Less
|
||||
```
|
17
【实践课外】15.结构体1/6-4 利用“选择排序算法“对结构体数组进行排序.c
Normal file
17
【实践课外】15.结构体1/6-4 利用“选择排序算法“对结构体数组进行排序.c
Normal file
@ -0,0 +1,17 @@
|
||||
p = p1;
|
||||
|
||||
for (p2 = p1 + 1; p2 < pData + n; p2++) {
|
||||
if (p2->score > p->score) {
|
||||
p = p2;
|
||||
}
|
||||
}
|
||||
|
||||
if (p != p1) {
|
||||
num = p->num;
|
||||
p->num = p1->num;
|
||||
p1->num = num;
|
||||
|
||||
score = p->score;
|
||||
p->score = p1->score;
|
||||
p1->score = score;
|
||||
}
|
73
【实践课外】15.结构体1/6-4 利用“选择排序算法“对结构体数组进行排序.md
Normal file
73
【实践课外】15.结构体1/6-4 利用“选择排序算法“对结构体数组进行排序.md
Normal file
@ -0,0 +1,73 @@
|
||||
# 6-4 利用“选择排序算法“对结构体数组进行排序
|
||||
|
||||
本题:补充函数 sortByChoose()的剩余部分,其要求是利用选择排序算法根据学生成绩(score)实现对结构体数组元素降序排序。
|
||||
|
||||
### 函数接口定义:
|
||||
```c++
|
||||
void sortByChoose(struct Student *pData,int n);
|
||||
```
|
||||
|
||||
### 裁判测试程序样例:
|
||||
```c++
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
#define N 10
|
||||
struct Student
|
||||
{
|
||||
int num;
|
||||
int score;
|
||||
};
|
||||
|
||||
void sortByChoose(struct Student *pData,int n);
|
||||
|
||||
int main(void)
|
||||
{
|
||||
struct Student data[10],*p;
|
||||
int i;
|
||||
|
||||
for(p=data,i=0;i<N;i++)
|
||||
{
|
||||
scanf("%d %d",&p->num,&p->score);
|
||||
p++;
|
||||
}
|
||||
sortByChoose(data,N);
|
||||
for (p=data,i=0;i<N;i++)
|
||||
{
|
||||
printf("%2d-%-5d", p->num, p->score);
|
||||
p++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void sortByChoose(struct Student *pData,int n)
|
||||
{
|
||||
struct Student *p1,*p2,*p;
|
||||
int num, score,i,j;
|
||||
for(p1=pData;p1<pData+n-1;p1++)
|
||||
{
|
||||
/* 请在这里填写答案 */
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 输入样例:
|
||||
|
||||
```in
|
||||
29 90
|
||||
15 80
|
||||
87 55
|
||||
65 84
|
||||
35 80
|
||||
33 55
|
||||
44 79
|
||||
99 80
|
||||
89 80
|
||||
41 55
|
||||
```
|
||||
|
||||
### 输出样例:
|
||||
|
||||
```out
|
||||
29-90 65-84 15-80 35-80 99-80 89-80 44-79 87-55 33-55 41-55
|
||||
```
|
13
【实践课外】15.结构体1/6-5 结构体的最值.c
Normal file
13
【实践课外】15.结构体1/6-5 结构体的最值.c
Normal file
@ -0,0 +1,13 @@
|
||||
ST* MaxST(ST d[], int n, int k) {
|
||||
ST* res = NULL;
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
if (d[i].gender == k) {
|
||||
if (res == NULL || d[i].scored > res->scored) {
|
||||
res = &d[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
66
【实践课外】15.结构体1/6-5 结构体的最值.md
Normal file
66
【实践课外】15.结构体1/6-5 结构体的最值.md
Normal file
@ -0,0 +1,66 @@
|
||||
# 6-5 结构体的最值
|
||||
|
||||
学生类型ST的定义如下:
|
||||
|
||||
typedef struct student{
|
||||
char name[10],id[10];
|
||||
int gender;
|
||||
int age;
|
||||
double scored;
|
||||
} ST;
|
||||
|
||||
编写函数,返回指定学生数组中的男生或女生的最高分的地址(约定:整数0和1分别代表男和女)。
|
||||
|
||||
### 函数接口定义:
|
||||
```c
|
||||
ST* MaxST(ST d[],int n,int k);//k=0|1
|
||||
```
|
||||
其中 `d` 是学生数组的初地址, `n`是数组的长度, `k` 是查找的性别描述(值确保是0或1),函数须返回指定类型学生中的最高分者的地址,如果不存在,返回空地址。
|
||||
|
||||
### 裁判测试程序样例:
|
||||
```c
|
||||
在这里给出函数被调用进行测试的例子。例如:
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
typedef struct student{
|
||||
char name[10],id[10];
|
||||
int gender;
|
||||
int age;
|
||||
double scored;
|
||||
} ST;
|
||||
void output(ST *d){//输出一个记录
|
||||
if(d==NULL) {printf("null\n");return;}
|
||||
printf("%s,%s,%d,%d,%4.2f\n",d->name,d->id,d->gender,d->age,d->scored);
|
||||
}
|
||||
ST* InitData(int n);//从输入设备上输入相关数据,略去不表
|
||||
|
||||
ST* MaxST(ST d[],int n,int k);//k=0|1 <--需要完成的函数:找最值
|
||||
|
||||
int main(){
|
||||
int i,n;scanf("%d\n",&n);
|
||||
ST *p=InitData(n);
|
||||
output(MaxST(p,n,0));
|
||||
output(MaxST(p,n,1));
|
||||
free(p);
|
||||
return 0;
|
||||
}
|
||||
/* 请在这里填写答案 */
|
||||
```
|
||||
|
||||
### 输入样例:
|
||||
第一行是记录个数,余下若干行是相关数据(以空格分隔,每行一个)。
|
||||
```in
|
||||
6
|
||||
Marry.MK 20201125 0 19 92.86
|
||||
J.Mark 20201185 0 17 90.93
|
||||
rouh.M 20201102 1 18 79.51
|
||||
byi.beee 20201129 1 17 90.28
|
||||
floyd.Fd 20201150 0 17 81.16
|
||||
grdda 20201146 1 19 85.52
|
||||
```
|
||||
### 输出样例:
|
||||
输出男,女同学中的最高分(只需要找出并返回其地址,输入,输出由测试程序完成)。
|
||||
```out
|
||||
Marry.MK,20201125,0,19,92.86
|
||||
byi.beee,20201129,1,17,90.28
|
||||
```
|
8
【实践课外】15.结构体1/6-6 复数相乘运算.c
Normal file
8
【实践课外】15.结构体1/6-6 复数相乘运算.c
Normal file
@ -0,0 +1,8 @@
|
||||
PLEX multi(PLEX a,PLEX b) {
|
||||
PLEX c;
|
||||
|
||||
c.re = a.re * b.re - a.im * b.im;
|
||||
c.im = a.re * b.im + a.im * b.re;
|
||||
|
||||
return c;
|
||||
}
|
51
【实践课外】15.结构体1/6-6 复数相乘运算.md
Normal file
51
【实践课外】15.结构体1/6-6 复数相乘运算.md
Normal file
@ -0,0 +1,51 @@
|
||||
# 6-6 复数相乘运算
|
||||
|
||||
本题要求实现一个函数,可计算两个复数相乘的积。
|
||||
|
||||
### 函数接口定义:
|
||||
```c++
|
||||
PLEX multi(PLEX a,PLEX b);
|
||||
```
|
||||
|
||||
其中 `a` 和 `b` 都是复数,返回值也为复数,值为a*b的值。
|
||||
|
||||
### 裁判测试程序样例:
|
||||
```c++
|
||||
#include <stdio.h>
|
||||
typedef struct
|
||||
{
|
||||
float re,im;
|
||||
}PLEX;
|
||||
|
||||
PLEX multi(PLEX a,PLEX b);
|
||||
|
||||
int main()
|
||||
{
|
||||
PLEX x,y,z;
|
||||
scanf("%f%f",&x.re,&x.im);
|
||||
scanf("%f%f",&y.re,&y.im);
|
||||
z=multi(x,y);
|
||||
if(z.im>=0)
|
||||
printf("%.2f+%.2fi",z.re,z.im);
|
||||
else
|
||||
printf("%.2f%.2fi",z.re,z.im);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* 请在这里填写答案 */
|
||||
```
|
||||
|
||||
### 输入样例:
|
||||
|
||||
|
||||
```in
|
||||
1 2
|
||||
3 4
|
||||
```
|
||||
|
||||
### 输出样例:
|
||||
|
||||
|
||||
```out
|
||||
-5.00+10.00i
|
||||
```
|
44
【实践课外】15.结构体1/7-5 一帮一.c
Normal file
44
【实践课外】15.结构体1/7-5 一帮一.c
Normal file
@ -0,0 +1,44 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#define FEMALE (0)
|
||||
#define MALE (1)
|
||||
|
||||
struct student {
|
||||
int gender; // 0 is female, 1 is male
|
||||
char name[10]; // the problem promises that the name will not exceed 8 characters
|
||||
int has_group;
|
||||
};
|
||||
|
||||
int n, pos[2];
|
||||
struct student students[55]; // the problem promises that the number of students will not exceed 50
|
||||
|
||||
int main() {
|
||||
scanf("%d", &n);
|
||||
|
||||
pos[FEMALE] = pos[MALE] = n;
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
scanf("%d %s", &students[i].gender, students[i].name);
|
||||
}
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
if (students[i].has_group) continue;
|
||||
|
||||
int current_gender = students[i].gender,
|
||||
target_gender = current_gender ^ 1;
|
||||
|
||||
for (pos[target_gender]--; pos[target_gender] >= 0; pos[target_gender]--) {
|
||||
if (students[pos[target_gender]].gender == target_gender
|
||||
&& !students[pos[target_gender]].has_group) {
|
||||
students[pos[target_gender]].has_group = 1;
|
||||
students[i].has_group = 1;
|
||||
|
||||
printf("%s %s\n", students[i].name, students[pos[target_gender]].name);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
32
【实践课外】15.结构体1/7-5 一帮一.md
Normal file
32
【实践课外】15.结构体1/7-5 一帮一.md
Normal file
@ -0,0 +1,32 @@
|
||||
# 7-5 一帮一
|
||||
|
||||
“一帮一学习小组”是中小学中常见的学习组织方式,老师把学习成绩靠前的学生跟学习成绩靠后的学生排在一组。本题就请你编写程序帮助老师自动完成这个分配工作,即在得到全班学生的排名后,在当前尚未分组的学生中,将名次最靠前的学生与名次最靠后的**异性**学生分为一组。
|
||||
|
||||
### 输入格式:
|
||||
|
||||
输入第一行给出正偶数`N`($$\le$$50),即全班学生的人数。此后`N`行,按照名次从高到低的顺序给出每个学生的性别(0代表女生,1代表男生)和姓名(不超过8个英文字母的非空字符串),其间以1个空格分隔。这里保证本班男女比例是1:1,并且没有并列名次。
|
||||
|
||||
### 输出格式:
|
||||
|
||||
每行输出一组两个学生的姓名,其间以1个空格分隔。名次高的学生在前,名次低的学生在后。小组的输出顺序按照前面学生的名次从高到低排列。
|
||||
|
||||
### 输入样例:
|
||||
```in
|
||||
8
|
||||
0 Amy
|
||||
1 Tom
|
||||
1 Bill
|
||||
0 Cindy
|
||||
0 Maya
|
||||
1 John
|
||||
1 Jack
|
||||
0 Linda
|
||||
```
|
||||
|
||||
### 输出样例:
|
||||
```out
|
||||
Amy Jack
|
||||
Tom Linda
|
||||
Bill Maya
|
||||
Cindy John
|
||||
```
|
34
【实践课外】15.结构体1/7-6 考试座位号.c
Normal file
34
【实践课外】15.结构体1/7-6 考试座位号.c
Normal file
@ -0,0 +1,34 @@
|
||||
#include <stdio.h>
|
||||
|
||||
struct student {
|
||||
char id[20]; // the problem promises that the id will not exceed 16 characters
|
||||
int seat1, seat2;
|
||||
};
|
||||
|
||||
int n, m;
|
||||
struct student students[1005]; // the problem promises that the number of students will not exceed 1000
|
||||
|
||||
int main() {
|
||||
scanf("%d", &n);
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
scanf("%s %d %d", students[i].id, &students[i].seat1, &students[i].seat2);
|
||||
}
|
||||
|
||||
scanf("%d", &m);
|
||||
|
||||
for (int i = 0; i < m; i++) {
|
||||
int seat;
|
||||
scanf("%d", &seat);
|
||||
|
||||
for (int j = 0; j < n; j++) {
|
||||
if (students[j].seat1 == seat) {
|
||||
printf("%s %d\n", students[j].id, students[j].seat2);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
32
【实践课外】15.结构体1/7-6 考试座位号.md
Normal file
32
【实践课外】15.结构体1/7-6 考试座位号.md
Normal file
@ -0,0 +1,32 @@
|
||||
# 7-6 考试座位号
|
||||
|
||||
“一帮一学习小组”是中小学中常见的学习组织方式,老师把学习成绩靠前的学生跟学习成绩靠后的学生排在一组。本题就请你编写程序帮助老师自动完成这个分配工作,即在得到全班学生的排名后,在当前尚未分组的学生中,将名次最靠前的学生与名次最靠后的**异性**学生分为一组。
|
||||
|
||||
### 输入格式:
|
||||
|
||||
输入第一行给出正偶数`N`($$\le$$50),即全班学生的人数。此后`N`行,按照名次从高到低的顺序给出每个学生的性别(0代表女生,1代表男生)和姓名(不超过8个英文字母的非空字符串),其间以1个空格分隔。这里保证本班男女比例是1:1,并且没有并列名次。
|
||||
|
||||
### 输出格式:
|
||||
|
||||
每行输出一组两个学生的姓名,其间以1个空格分隔。名次高的学生在前,名次低的学生在后。小组的输出顺序按照前面学生的名次从高到低排列。
|
||||
|
||||
### 输入样例:
|
||||
```in
|
||||
8
|
||||
0 Amy
|
||||
1 Tom
|
||||
1 Bill
|
||||
0 Cindy
|
||||
0 Maya
|
||||
1 John
|
||||
1 Jack
|
||||
0 Linda
|
||||
```
|
||||
|
||||
### 输出样例:
|
||||
```out
|
||||
Amy Jack
|
||||
Tom Linda
|
||||
Bill Maya
|
||||
Cindy John
|
||||
```
|
Loading…
Reference in New Issue
Block a user