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;
}