1 #include <cstdio>
 2 #include <iostream>
 3 
 4 using namespace std;
 5 
 6 struct stu
 7 {
 8     char num[5];
 9     char name[11];
10     int base;
11     int oper;
12     int total;
13 }a[100],t;
14 
15 int main()
16 {
17     int i,j,k,temp1,temp2;
18     FILE *fp;
19     if((fp=fopen("in1.dat","r"))==NULL)
20     {
21         printf("文件打开失败\n");
22         exit(0);
23     }
24     for(i=0;i<100;++i)
25     {
26         fscanf(fp,"%s",a[i].num);
27         fscanf(fp,"%s",a[i].name);
28         fscanf(fp,"%d",&a[i].base);
29         fscanf(fp,"%d",&a[i].oper);
30         fscanf(fp,"%d",&a[i].total);
31         a[i].total=a[i].base+a[i].oper;
32     }
33     for(i=99;i>=0;--i)
34     {
35         for(j=0;j<i;++j)
36         {
37             if(a[j].total<a[j+1].total)
38             {
39                 t=a[j];
40                 a[j]=a[j+1];
41                 a[j+1]=t;
42             }
43             else if(a[j].total==a[j+1].total)
44             {
45                 temp1=temp2=0;
46                 for(k=0;k<4;++k)
47                 {
48                     temp1*=10;
49                     temp1+=a[j].num[k]-'0';
50                     temp2*=10;
51                     temp2+=a[j+1].num[k]-'0';
52                 }
53                 if(temp2<temp1)
54                 {
55                     t=a[j];
56                     a[j]=a[j+1];
57                     a[j+1]=t;
58                 }
59             }
60         }
61     }
62 
63     for(i=0,j=0;i<100;++i)
64     {
65         if(j==10)
66             break;
67         if(a[i].base>=10&&a[i].oper>=10)
68         {
69             ++j;
70             printf("%s\t%s\t%d\t%d\t%d\n",a[i].num,a[i].name,a[i].base,a[i].oper,a[i].total);
71         }
72     }
73     fclose(fp);
74     return 0;
75 }

 

posted on 2013-04-09 12:44  可笑痴狂  阅读(219)  评论(0编辑  收藏  举报