题解 | 查找学生信息
查找学生信息
https://www.nowcoder.com/practice/fe8bff0750c8448081759f3ee0d86bb4
#include <stdio.h> #include <string.h> #define data_len 1000 typedef struct student { char nums[20]; char name[20]; char sex[10]; int age; }student; int main() { int n; int m; struct student stu[data_len]; while (scanf("%d", &n) != EOF) { for (int i = 0; i < n; i++) { scanf("%s %s %s %d", stu[i].nums, stu[i].name, stu[i].sex, &stu[i].age); } scanf("%d", &m); for (int i = 0; i < m; i++) { char query[20]; scanf("%s", query); // 查找 int j; for(j=0; j<n; j++){ if(strcmp(query, stu[j].nums) == 0){ printf("%s %s %s %d\n", stu[j].nums, stu[j].name, stu[j].sex, stu[j].age); break; } } if(j==n) printf("%s\n", "No Answer!"); } } return 0; }