当前位置:网站首页>7-1 链表也简单fina
7-1 链表也简单fina
2022-07-05 18:22:00 【mxrone】
将学生成绩绩点组成一个链表。链表结构如下:
struct student {
string name; //学生姓名
double gpa; //绩点
student *next;
};
输入是一组学生的姓名和绩点,以链表形式存储。 删除绩点小于平均绩点的学生结点,成为一个新链表。 后按照输入的顺序,依序输出新链表的学生信息。平均绩点是输入的所有学生绩点取算术平均值。
输入格式:
输入包括若干行。 每行是一个学生的 姓名和绩点,以空格隔开。
最后一行是-1。
输出格式:
输出包括学生姓名。 每个学生姓名一行。
输入样例:
zhang 3.5
liu 2.1
tie 1.9
-1
输出样例:
zhang
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct stu {
char name[20];
double s;
struct stu *next;
};
struct stu *create();
struct stu *del(struct stu *head,double score);
double average(struct stu *head);
void printlist(struct stu *head);
int main()
{
double s;
struct stu *head=NULL;
head=create();
s=average(head);
head=del(head,s);
printlist(head);
return 0;
}
struct stu *create()
{
struct stu *head=NULL,*p,*tail;
char name[20];
while(1)
{
scanf("%s",name);
if(name[0]=='-')
break;
p=(struct stu *)malloc(sizeof(struct stu));
strcpy(p->name,name);
scanf("%lf",&p->s);
if(head==NULL)
{
head=tail=p;
}
else
{
tail->next=p;
}
tail=p;
}
tail->next = NULL;
return head;
}
struct stu *del(struct stu *head,double score)
{
struct stu *p,*p1;
while(head!=NULL&&head->s<score)
{
p=head;
head=head->next ;
free(p);
}
if(head==NULL) return NULL;
p=head,p1=head->next ;
while(p1!=NULL)
{
if(p1->s <score)
{
p->next = p1->next ;
free(p1);
}
else
{
p=p->next;
}
p1=p->next ;
}
return head;
}
double average(struct stu *head)
{
double s=0,count=0;
struct stu *p;
for(p=head;p!=NULL;p=p->next)
{
s+=p->s;
count++;
}
s=s/count;
return s;
}
void printlist(struct stu *head)
{
struct stu *p;
for(p=head;p!=NULL;p=p->next)
{
printf("%s\n",p->name);
}
}
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct stu {
char name[20];
double s;
struct stu *next;
};
struct stu *del(struct stu *head,double score);
int main()
{
double s;
int count=0;
struct stu *head=NULL,*p,*tail;
char name[20];
while(1)
{
scanf("%s",name);
if(name[0]=='-')
break;
p=(struct stu *)malloc(sizeof(struct stu));
strcpy(p->name,name);
scanf("%lf",&p->s);
s+=p->s;
if(head==NULL)
{
head=tail=p;
}
else
{
tail->next=p;
}
tail=p;
count++;
}
tail->next = NULL;
s=s/count;
for(p=head;p!=NULL;p=p->next)
{
if(p->s>s){
printf("%s\n",p->name);
}
}
return 0;
}
边栏推荐
- buuctf-pwn write-ups (9)
- node_ Exporter memory usage is not displayed
- 案例分享|金融业数据运营运维一体化建设
- Image classification, just look at me!
- websocket 工具的使用
- Share: ZTE Yuanhang 30 Pro root unlock BL magick ZTE 7532n 8040n 9041n brush mask original brush package root method Download
- Huaxia Fund: sharing of practical achievements of digital transformation in the fund industry
- Is it complicated to open an account? Is online account opening safe?
- Matlab built-in function how different colors, matlab subsection function different colors drawing
- 生词生词生词生词[2]
猜你喜欢
nano的CAN通信
LeetCode 6111. 螺旋矩阵 IV
使用Jmeter虚拟化table失败
ConvMAE(2022-05)
吴恩达团队2022机器学习课程,来啦
U-Net: Convolutional Networks for Biomedical Images Segmentation
websocket 工具的使用
@Extension, @spi annotation principle
Simulate the hundred prisoner problem
Sophon autocv: help AI industrial production and realize visual intelligent perception
随机推荐
Sophon base 3.1 launched mlops function to provide wings for the operation of enterprise AI capabilities
Login and connect CDB and PDB
websocket 工具的使用
让更多港澳青年了解南沙特色文创产品!“南沙麒麟”正式亮相
Access the database and use redis as the cache of MySQL (a combination of redis and MySQL)
如何获取飞机穿过雷达两端的坐标
About Estimation with Cross-Validation
English sentence pattern reference
爱因斯坦求和einsum
[PM2 details]
Clickhouse (03) how to install and deploy Clickhouse
Pytorch yolov5 training custom data
FCN: Fully Convolutional Networks for Semantic Segmentation
How to choose the most formal and safe external futures platform?
Is it safe to open an account, register and dig money? Is there any risk? Is it reliable?
Find the first k small element select_ k
Star Ring Technology launched transwarp Navier, a data element circulation platform, to help enterprises achieve secure data circulation and collaboration under privacy protection
Huaxia Fund: sharing of practical achievements of digital transformation in the fund industry
[utiliser Electron pour développer le Bureau sur youkirin devrait]
Use JMeter to record scripts and debug