建立一个线性表,求平均成绩 (越快分越多)
1、建立一个线性表,求平均成绩
2、将该线性表倒置,删除小于60的记录,并输出结果 C语言实现
[解决办法]
你这平均成绩是指算数平均分?
这个似乎也不是很难的定义个struct数组然后就可以解决了。
[解决办法]
用STL来解决。这个很快的!!
[解决办法]
看楼主的头像不错。把以前写的作业拿出来了。
#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;}
[解决办法]