|
发表于 2020-5-16 16:09:01
|
显示全部楼层
试着写了下
- #include<stdio.h>
- #include<malloc.h>
- struct People
- {
- char name[9];
- float te;
- int ju;
- struct People *next;
- };
- void getpeople(struct People *person)
- {
- scanf("%s %f %d",person->name,&person->te,&person->ju);
- }
- void outpeople(struct People *person)
- {
- printf("%s\n",person->name);
- }
- void addpeople(struct People **head)
- { struct People *person,*rear;
- person=(struct people *)malloc(sizeof(struct People));
- if(person==NULL)
- {
- fprintf(stderr,"申请内存失败!\n");
- }
- getpeople(person);
- if(*head==NULL)
- {
- *head=person;
- person->next=NULL;
- }
- else
- {
-
- rear->next=person;
- person->next=NULL;
- }
- rear=person;
- }
- int main()
- {
- int n,i,count=0;
- scanf("%d",&n);
- struct People *head=NULL;
- struct People *person;
- for(i=0;i<n;i++)
- {
- addpeople(&head);
- }
- person=head;
- putchar('\n');
- while(person!=NULL)
- {
- if((person->te>=37.5)&&(person->ju==1))
- {
- outpeople(person);
- person=person->next;
- count++;
- continue;
- }
- person=person->next;
- }
- printf("%d\n",count);
- }
复制代码 |
|