#include<stdio.h> #include<string.h> typedef struct { char name[20]; char sex[20]; int year; int month; int day; }Stu; int main() { Stu stu[1001]; char Name[1001],Sex[1001]; char str[1001]; int i=0; while(scanf("%s",&str)!=EOF) { if(strcmp(str,"quit")==0) break; else { if(strcmp(str,"add")==0) { scanf("%s %s %d %d %d",&stu[i].name,&stu[i].sex,&stu[i].year,&stu[i].month,&stu[i].day); i++; } if(strcmp(str,"name")==0) { scanf("%s",&Name); for(int j=0;j<i;j++) { if(strcmp(stu[j].name,Name)==0) { printf("%s %s %d-%d-%d\n",stu[j].name,stu[j].sex,stu[j].year,stu[j].month,stu[j].day); } } } if(strcmp(str,"sex")==0) { scanf("%s",&Sex); for(int j=0;j<i;j++) { if(strcmp(stu[j].sex,Sex)==0) { printf("%s %s %d-%d-%d\n",stu[j].name,stu[j].sex,stu[j].year,stu[j].month,stu[j].day); } } } } } return 0; } |
Double click to view unformatted code.