当前位置:网站首页>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;
}
边栏推荐
- 音视频包的pts,dts,duration的由来.
- 快速生成ipa包
- 【PaddlePaddle】 PaddleDetection 人脸识别 自定义数据集
- Use JMeter to record scripts and debug
- pytorch yolov5 训练自定义数据
- Star ring technology data security management platform defender heavy release
- 开户注册挖财安全吗?有没有风险的?靠谱吗?
- 瀚升优品app翰林优商系统开发功能介绍
- [QNX Hypervisor 2.2用户手册]6.3.2 配置VM
- Access the database and use redis as the cache of MySQL (a combination of redis and MySQL)
猜你喜欢

buuctf-pwn write-ups (9)

FCN: Fully Convolutional Networks for Semantic Segmentation

Record a case of using WinDbg to analyze memory "leakage"

案例分享|金融业数据运营运维一体化建设

Pytorch yolov5 training custom data

websocket 工具的使用

FCN: Fully Convolutional Networks for Semantic Segmentation

爬虫01-爬虫基本原理讲解

Huaxia Fund: sharing of practical achievements of digital transformation in the fund industry

@Extension、@SPI注解原理
随机推荐
rust统计文件中单词出现的次数
关于服装ERP,你想知道的都在这里了
Trust counts the number of occurrences of words in the file
Clickhouse (03) how to install and deploy Clickhouse
Is it safe to open an account and register stocks for stock speculation? Is there any risk? Is it reliable?
图扑软件数字孪生 | 基于 BIM 技术的可视化管理系统
Fix vulnerability - mysql, ES
Sophon kg upgrade 3.1: break down barriers between data and liberate enterprise productivity
Vulnhub's darkhole_ two
文章中的逻辑词
[QNX hypervisor 2.2 user manual]6.3.2 configuring VM
buuctf-pwn write-ups (9)
Notes on common management commands of openshift
Let more young people from Hong Kong and Macao know about Nansha's characteristic cultural and creative products! "Nansha kylin" officially appeared
记录Pytorch中的eval()和no_grad()
Can communication of nano
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
Deep copy and shallow copy [interview question 3]
Sibling components carry out value transfer (there is a sequence displayed)
【HCIA-cloud】【1】云计算的定义、什么是云计算、云计算的架构与技术说明、华为云计算产品、华为内存DDR配置工具说明