69,371
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct Node
{
char name[20];
float score;
struct Node* next;
}*LinkList;
void Reverse(LinkList head)
{
LinkList p1 = head,p2 = head->next,p3;
p1->next = NULL;
while(p2)
{
p3 = p2->next;
p2->next = p1->next;
p1->next = p2;
p2 = p3;
}
}
void DelUnder60(LinkList head)
{
LinkList p1 = head->next,p2,p3=head;
while(p1)
{
p2 = p1->next;
if (p1->score<60)
{
free(p1);
p3->next = p2;
p1 = p2;
}
else
{
p3 = p3->next;
p1 = p1->next;
}
}
}
void OutPut(LinkList head)
{
LinkList p = head->next;
while(p)
{
printf("name is %s and score = %f\n",p->name,p->score);
p = p->next;
}
printf("\n");
}
int main()
{
char Tmp[20];
float meanScore=0.00;
int nCount=0;
LinkList tmp,p;
LinkList head = (LinkList)malloc(sizeof(struct Node));
head->next = NULL;
p = head;
while(scanf("%s",Tmp)!=EOF)
{
nCount++;
tmp = (LinkList)malloc(sizeof(struct Node));
strcpy(tmp->name,Tmp);
scanf("%f",&tmp->score);
meanScore += tmp->score;
tmp->next = p->next;
p->next = tmp;
p = tmp;
}
meanScore /= nCount;
printf("%f\n",meanScore);
OutPut(head);
Reverse(head);
OutPut(head);
DelUnder60(head);
OutPut(head);
return 0;
}