Fork me on GitHub

 1 #include "stdio.h"
 2 #include "stdlib.h"
 3 #include "string.h"
 4 #include "math.h"
 5 typedef struct stu
 6 {
 7     char num[100];//尽量开大数组
 8     char name[100];
 9     char sex[3];
10     int age;
11 }stu;
12 int main()
13 {
14     int n,m,exist;
15     int i,j;
16     char temp[100];
17     stu *a=(stu*)malloc(1000*sizeof(stu));
18     while(scanf("%d",&n)!=EOF)
19     {
20         for(i=0;i<n;i++)
21             scanf("%s %s %s %d",&a[i].num,&a[i].name,&a[i].sex,&a[i].age);
22         scanf("%d",&m);
23         for(i=0;i<m;i++)
24         {
25             exist=0;
26             scanf("%s",temp);
27             for(j=0;j<n;j++)//这里是n而非m,n个学生!
28             {
29                 if(strcmp(temp,a[j].num)==0)
30                 {
31                     exist=1;
32                     printf("%s %s %s %d\n",a[j].num,a[j].name,a[j].sex,a[j].age);
33                     break;//节省时间!
34                 }
35             }
36             if (j==n&&exist==0)
37                     printf("No Answer!\n");
38         }        
39     }
40     return 0;
41 }

 

posted on 2013-01-12 13:16  huashiyiqike  阅读(155)  评论(0编辑  收藏  举报