当前位置:网站首页>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;
}
边栏推荐
- Electron installation problems
- 如何获取飞机穿过雷达两端的坐标
- Generate classes from XML schema
- 怎么自动安装pythn三方库
- 瞅一瞅JUC提供的限流工具Semaphore
- Check namespaces and classes
- 《2022中国信创生态市场研究及选型评估报告》发布 华云数据入选信创IT基础设施主流厂商!
- [QNX Hypervisor 2.2用户手册]6.3.2 配置VM
- Is it safe to open an account and register stocks for stock speculation? Is there any risk? Is it reliable?
- To solve the stubborn problem of Lake + warehouse hybrid architecture, xinghuan Technology launched an independent and controllable cloud native Lake warehouse integrated platform
猜你喜欢
瞅一瞅JUC提供的限流工具Semaphore
Privacy computing helps secure data circulation and sharing
IDEA配置npm启动
node_ Exporter memory usage is not displayed
爬虫01-爬虫基本原理讲解
To solve the stubborn problem of Lake + warehouse hybrid architecture, xinghuan Technology launched an independent and controllable cloud native Lake warehouse integrated platform
【HCIA-cloud】【1】云计算的定义、什么是云计算、云计算的架构与技术说明、华为云计算产品、华为内存DDR配置工具说明
Use JMeter to record scripts and debug
Tupu software digital twin | visual management system based on BIM Technology
Nanjing University: Discussion on the training program of digital talents in the new era
随机推荐
Failed to virtualize table with JMeter
Use of print function in MATLAB
Vulnhub's darkhole_ two
Le cours d'apprentissage de la machine 2022 de l'équipe Wunda arrive.
The 2022 China Xinchuang Ecological Market Research and model selection evaluation report released that Huayun data was selected as the mainstream manufacturer of Xinchuang IT infrastructure!
Is it safe for golden sun to open an account? Can I open an account free of 5 in case?
项目中遇到的问题 u-parse 组件渲染问题
7-1 链表也简单fina
快速生成ipa包
RPC protocol details
ViewPager + RecyclerView的内存泄漏
Matlab built-in function how different colors, matlab subsection function different colors drawing
MYSQL中 find_in_set() 函数用法详解
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
[paddlepaddle] paddedetection face recognition custom data set
websocket 工具的使用
How to obtain the coordinates of the aircraft passing through both ends of the radar
Is it complicated to open an account? Is online account opening safe?
The main thread anr exception is caused by too many binder development threads
RPC协议详解