1
0
mirror of https://github.com/renbaoshuo/202401-programming-assignments.git synced 2024-12-16 15:44:39 +00:00

【实践课内】16.结构体2

This commit is contained in:
Baoshuo Ren 2024-12-13 16:44:49 +08:00 committed by GitHub
parent 01c7825e24
commit f4a8b739f9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 122 additions and 0 deletions

View File

@ -0,0 +1,22 @@
#include <stdio.h>
struct person {
char name[10];
double basic, floating, outlay;
};
int n;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
struct person p;
scanf("%s %lf %lf %lf", p.name, &p.basic, &p.floating, &p.outlay);
printf("%s %.2lf\n", p.name, p.basic + p.floating - p.outlay);
}
return 0;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 372 KiB

View File

@ -0,0 +1,32 @@
#include <stdio.h>
struct student {
char id[10], name[10];
int score;
};
int n;
double avg;
struct student stu[10];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%s %s %d", stu[i].id, stu[i].name, &stu[i].score);
avg += stu[i].score;
}
avg /= n;
printf("%.2lf\n", avg);
for (int i = 0; i < n; i++) {
if (stu[i].score < avg) {
printf("%s %s\n", stu[i].name, stu[i].id);
}
}
return 0;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 382 KiB

View File

@ -0,0 +1,34 @@
#include <stdio.h>
struct student {
char id[10], name[10];
int score[3];
int sum_score;
};
int n, max_id;
struct student stu[10];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%s %s", stu[i].id, stu[i].name);
for (int j = 0; j < 3; j++) {
scanf("%d", &stu[i].score[j]);
stu[i].sum_score += stu[i].score[j];
}
}
for (int i = 1; i < n; i++) {
if (stu[i].sum_score > stu[max_id].sum_score) {
max_id = i;
}
}
printf("%s %s %d\n", stu[max_id].name, stu[max_id].id, stu[max_id].sum_score);
return 0;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 387 KiB

View File

@ -0,0 +1,34 @@
#include <stdio.h>
struct contact {
char name[15], birthday[15], gender, tel[20], phone[20];
};
int n, k;
struct contact contacts[15];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%s %s %c %s %s\n", contacts[i].name, contacts[i].birthday, &contacts[i].gender, contacts[i].tel, contacts[i].phone);
}
scanf("%d", &k);
for (int i = 0; i < k; i++) {
int x;
scanf("%d", &x);
if (x < 0 || x >= n) {
printf("Not Found\n");
continue;
}
printf("%s %s %s %c %s\n", contacts[x].name, contacts[x].tel, contacts[x].phone, contacts[x].gender, contacts[x].birthday);
}
return 0;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 536 KiB