当前位置:网站首页>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;
}
边栏推荐
- Trust counts the number of occurrences of words in the file
- Various pits of vs2017 QT
- RPC protocol details
- 文章中的逻辑词
- Generate XML schema from class
- Is it safe for Apple mobile phone to speculate in stocks? Is it a fraud to get new debts?
- Insufficient picture data? I made a free image enhancement software
- U-Net: Convolutional Networks for Biomedical Images Segmentation
- Logical words in Articles
- 爬虫01-爬虫基本原理讲解
猜你喜欢
Image classification, just look at me!
LeetCode 6111. Spiral matrix IV
Nacos distributed transactions Seata * * install JDK on Linux, mysql5.7 start Nacos configure ideal call interface coordination (nanny level detail tutorial)
让更多港澳青年了解南沙特色文创产品!“南沙麒麟”正式亮相
Pytorch yolov5 training custom data
基于can总线的A2L文件解析(3)
使用JMeter录制脚本并调试
Share: ZTE Yuanhang 30 Pro root unlock BL magick ZTE 7532n 8040n 9041n brush mask original brush package root method Download
图片数据不够?我做了一个免费的图像增强软件
U-Net: Convolutional Networks for Biomedical Images Segmentation
随机推荐
Sibling components carry out value transfer (there is a sequence displayed)
Use JMeter to record scripts and debug
How to choose the most formal and safe external futures platform?
【PaddleClas】常用命令
瀚升优品app翰林优商系统开发功能介绍
node_exporter内存使用率不显示
LeetCode 6109. Number of people who know the secret
RPC protocol details
All you want to know about clothing ERP is here
websocket 工具的使用
Writing writing writing
【pm2详解】
The 10th global Cloud Computing Conference | Huayun data won the "special contribution award for the 10th anniversary of 2013-2022"
Quickly generate IPA package
Introduction to VC programming on "suggestions collection"
ClickHouse(03)ClickHouse怎么安装和部署
SAP feature description
Reptile 01 basic principles of reptile
Memory management chapter of Kobayashi coding
sample_rate(采樣率),sample(采樣),duration(時長)是什麼關系