文章
19
粉丝
225
获赞
20
访问
52.2k
将所有的的信息存入一个结构体数组中
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct stu {
char num[50];
char name[50];
char sex[50];
int age;
};
void out(struct stu s[], int n, char num[]) {
int count = 0;
for (int i = 0; i < n; i++) {
if (strcmp(num, s[i].num) == 0) {
printf("%s %s %s %d\n", s[i].num, s[i].name, s[i].sex, s[i].age);
break;
}
else
count++;
}
if (count == n)
printf("No Answer!\n");
}
int main() {
int n, m;
char num[50];
scanf("%d", &n);
struct stu* s = (struct stu*)malloc(sizeof(struct stu) * n);
for (int i = 0; i < n; i++)
scanf("%s%s%s%d", s[i].num, s[i].name, s[i].sex, &s[i].age);
scanf("%d", &m);
for (int i = 0; i < m; i++) {
scanf("%s", num);
out(s, n, num);
}
return 0;
}
登录后发布评论
暂无评论,来抢沙发