求指导:班上有30个学生,给出姓名、出生日期、学号、专业等信息,编程根据学号查找学生的信息并输出
Description班上有30个学生,给出姓名、出生日期、学号、专业等信息,编程根据学号查找学生的信息并输出。
定义一个 struct student 来完成本题。
Input
首先是30行,每行一个学生的信息,分别是 姓名(小于32个字符)、生日(8位数字)、学号(8位数字)、专业(小于32个字符),以空格分隔。
然后是一个n,表示有n个查询
接下来n行,每行一个学号。
Output
对于每一个学号,输出学生的信息,一行中包含姓名、生日(8位数字)、学号(8位数字,不足的左边补0)、专业。
如果学号没有对应学生信息,输出一行“Not found”
Sample Input
高昊 19000101 00112233 计算机
陈越东 19000101 00112234 计算机
黄庆乐 19000101 00112235 计算机
屠鹏博 19000101 00112236 计算机
田伟 19000101 00112237 计算机
王江 19000101 00112238 计算机
(...以及后续24个学生的信息,略)
2
00112233
12345678
Sample Output
高昊 19000101 00112233 计算机
Not found
以上是问题的要求,小弟我基本程序语句只知道一些,不知道怎么用结构体,求赐教~~~谢谢了
程序代码:#include <stdio.h>
#include <malloc.h>
#include <string.h>
#include <stdlib.h>
#define NULL 0
#define LEN sizeof(struct student)
struct student{
char name[33];
long int birthday;
long int order;
char major[33];
struct student *next;
};
void seek();
int main(){
int i,s,k;
for(i=0;i<30;i++){
struct student *p0;
p0 = (struct student *)malloc(LEN);
scanf ("%s",p0->name);
scanf ("%ld",&p0->birthday);
scanf ("%ld",&p0->order);
scanf ("%s",p0->major);
}
scanf("%d",&k);
for(s=0;s<k;s++){
seek();
}
return 0;
}
void seek()
{
int order;
struct student *p1;
scanf("%ld", &order);
if(head==NULL)
{
printf("Not found\n");
return;
}
p1 = head;
while (order!=p1->order && p1->next!=NULL)
p1 = p1->next;
if (order == p1->order)
{
printf ("%s %ld %d %s\n", p1->name, p1->birthday, p1->order, p1->major);
}
else
printf ("Not found\n");
}这是之前参考大神代码写的,但是连编译都过不了,还有好多地方自己都看不懂









