当前位置:网站首页>7-1 linked list is also simple fina
7-1 linked list is also simple fina
2022-07-05 18:32:00 【mxrone】
Form a linked list of students' grades . The structure of the list is as follows :
struct student {
string name; // The student's name
double gpa; // Grade point
student *next;
};
The input is the name and grade point of a group of students , Store as a linked list . Delete the student node whose grade point is less than the average grade point , Become a new linked list . Then follow the order of input , Output the student information of the new linked list in order . GPA is the arithmetic mean of all student grades entered .
Input format :
The input consists of several lines . Each line is for a student Name and grade point , Space off .
The last line is -1.
Output format :
Output includes student name . One line for each student's name .
sample input :
zhang 3.5
liu 2.1
tie 1.9
-1
sample output :
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;
}
边栏推荐
- Personal understanding of convolutional neural network
- About Statistical Power(统计功效)
- 爱因斯坦求和einsum
- websocket 工具的使用
- rust统计文件中单词出现的次数
- sample_rate(采樣率),sample(采樣),duration(時長)是什麼關系
- Is it complicated to open an account? Is online account opening safe?
- 兄弟组件进行传值(显示有先后顺序)
- 【HCIA-cloud】【1】云计算的定义、什么是云计算、云计算的架构与技术说明、华为云计算产品、华为内存DDR配置工具说明
- How can cluster deployment solve the needs of massive video access and large concurrency?
猜你喜欢
pytorch yolov5 训练自定义数据
How to automatically install pythn third-party libraries
第十届全球云计算大会 | 华云数据荣获“2013-2022十周年特别贡献奖”
How to obtain the coordinates of the aircraft passing through both ends of the radar
A2L file parsing based on CAN bus (3)
如何写出好代码 - 防御式编程
Fix vulnerability - mysql, ES
Thoroughly understand why network i/o is blocked?
吳恩達團隊2022機器學習課程,來啦
The 11th China cloud computing standards and Applications Conference | cloud computing national standards and white paper series release, and Huayun data fully participated in the preparation
随机推荐
The 11th China cloud computing standards and Applications Conference | China cloud data has become the deputy leader unit of the cloud migration special group of the cloud computing standards working
Multithreading (I) processes and threads
【PaddleClas】常用命令
How to choose the most formal and safe external futures platform?
Can communication of nano
[QNX hypervisor 2.2 user manual]6.3.2 configuring VM
Use of print function in MATLAB
Pytorch yolov5 training custom data
U-Net: Convolutional Networks for Biomedical Images Segmentation
Introduction to the development function of Hanlin Youshang system of Hansheng Youpin app
Problems encountered in the project u-parse component rendering problems
Leetcode notes: Weekly contest 300
Electron installation problems
ClickHouse(03)ClickHouse怎么安装和部署
About Estimation with Cross-Validation
The 11th China cloud computing standards and Applications Conference | cloud computing national standards and white paper series release, and Huayun data fully participated in the preparation
IDEA配置npm启动
《ClickHouse原理解析与应用实践》读书笔记(5)
Electron安装问题
Cronab log: how to record the output of my cron script