#include<stdio.h> #include<string.h> struct stu{ char name[20]; char sex[20]; int year; int month; int day; }; void show(stu student){ printf("%s %s %d-%d-%d\n",student.name,student.sex,student.year,student.month,student.day); } int main(){ char order[20]; char name[20],sex[20]; stu student[30]; int i=0,j; while(1){ scanf("%s",order); if(strcmp(order,"quit")==0){ break; } else if(strcmp(order,"add")==0){ scanf("%s%s%d%d%d",student[i].name,student[i].sex,&student[i].year,&student[i].month,&student[i].day); i++; } else if(strcmp(order,"name")==0){ scanf("%s",name); for(j=0;j<i;j++){ if(strcmp(name,student[j].name)==0){ show(student[j]); } } } else if(strcmp(order,"sex")==0){ scanf("%s",sex); for(j=0;j<i;j++){ if(strcmp(sex,student[j].sex)==0){ show(student[j]); } } } } } |
Double click to view unformatted code.