当前位置:网站首页>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;
}
边栏推荐
- About statistical power
- Image classification, just look at me!
- rust统计文件中单词出现的次数
- 使用JMeter录制脚本并调试
- ConvMAE(2022-05)
- Pytorch yolov5 training custom data
- Writing writing writing
- 爱因斯坦求和einsum
- 分享:中兴 远航 30 pro root 解锁BL magisk ZTE 7532N 8040N 9041N 刷机 刷面具原厂刷机包 root方法下载
- Exemple Quelle est la relation entre le taux d'échantillonnage, l'échantillon et la durée?
猜你喜欢
使用JMeter录制脚本并调试
LeetCode 6109. 知道秘密的人数
Maximum artificial island [how to make all nodes of a connected component record the total number of nodes? + number the connected component]
To solve the stubborn problem of Lake + warehouse hybrid architecture, xinghuan Technology launched an independent and controllable cloud native Lake warehouse integrated platform
Isprs2022 / Cloud Detection: Cloud Detection with Boundary nets Boundary Networks Based Cloud Detection
Privacy computing helps secure data circulation and sharing
彻底理解为什么网络 I/O 会被阻塞?
使用Jmeter虚拟化table失败
rust统计文件中单词出现的次数
LeetCode 6111. 螺旋矩阵 IV
随机推荐
兄弟组件进行传值(显示有先后顺序)
OpenShift常用管理命令杂记
含重复元素取不重复子集[如何取子集?如何去重?]
使用Jmeter虚拟化table失败
LeetCode 6111. Spiral matrix IV
How to improve the thermal management in PCB design with the effective placement of thermal through holes?
@Extension、@SPI注解原理
音视频包的pts,dts,duration的由来.
快速生成ipa包
Wu Enda team 2022 machine learning course, coming
Is it safe to open an account and register stocks for stock speculation? Is there any risk? Is it reliable?
The 10th global Cloud Computing Conference | Huayun data won the "special contribution award for the 10th anniversary of 2013-2022"
最大人工岛[如何让一个连通分量的所有节点都记录总节点数?+给连通分量编号]
Whether to take a duplicate subset with duplicate elements [how to take a subset? How to remove duplicates?]
Multithreading (I) processes and threads
生词生词生词生词[2]
Star Ring Technology launched transwarp Navier, a data element circulation platform, to help enterprises achieve secure data circulation and collaboration under privacy protection
Share: ZTE Yuanhang 30 Pro root unlock BL magick ZTE 7532n 8040n 9041n brush mask original brush package root method Download
Privacy computing helps secure data circulation and sharing
Le cours d'apprentissage de la machine 2022 de l'équipe Wunda arrive.