title:輸入若干個學生的資訊(包括學號、姓名和成績),輸入學號為0時輸入結束。建立一個單向鏈表,再輸入一個成績值,將成績大於等於該值的學生資訊輸出。
input:3n+2行,每3行為一個學生的資訊,分別為學號,姓名和成績。倒數第二行為0,表示輸入結束。最後一行為一個整數,代表分數。
output:若干行,每三行代表一個學生的資訊。
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct stud_node{
int long num;
char name[20];
int score;
struct stud_node *next;
};
int main()
{ int size,score;char name[20];int long num;
struct stud_node *head, *tail,*p,*ptr;
head = tail = NULL;
size = sizeof(struct stud_node);
scanf("%ld", &num);
while(num!=0)
{
scanf("%s%d", name, &score);
p=(struct stud_node *) malloc(size);
p->num =num;
strcpy(p->name, name);
p->score = score;
p->next = NULL;
if(head == NULL)
head = p;
else
tail->next = p;
tail=p;
scanf("%ld", &num);
}
ints;
scanf("%d",&s);
//printf("%d",s);
for(ptr=head;ptr!=NULL;ptr=ptr->next)
if(ptr->score >= s)
printf("%ld\n%s\n%d\n",ptr->num,ptr->name,ptr->score);
return 0; }