#include #include #include #define MAXLEN 256 struct RecForn{ long Key1; long Key2; }rec[1001]; void main(int argc, char *argv[]) { static char Line[MAXLEN]; int i, j, Cnt; int Start, End; FILE *Infp, *Outfp; static Temp3[4], Temp6[7]; char Item1; long Item2, Item3; long ExTemp; Start=atoi(argv[1]); End=atoi(argv[2]); Infp=fopen("C:\\TC\\Output\\abc2125.txt","rt"); Cnt=0; rec[5].Key2=0; for(i=1;i<=End;i++){ fgets(Line, MAXLEN, Infp); if(i>=Start){ Item1=*(Line+12); Item2=atol(strncpy(Temp3, Line+19, 3)); Item3=atol(strncpy(Temp3, Line+23, 3)); if((Item1='B')||(Item1='C')){ Cnt++; rec[Cnt].Key1=atol(strncpy(Temp6, Line+0, 6)); rec[Cnt].Key2=Item2*Item3; } } } for(i=1;i<=Cnt-1;i++) for(j=i+1;j<=Cnt;j++) if((rec[i].Key2rec[j].Key1))){ ExTemp=rec[i].Key1; rec[i].Key1=rec[j].Key1; rec[j].Key1=ExTemp; ExTemp=rec[i].Key2; rec[i].Key2=rec[j].Key2; rec[j].Key2=ExTemp; } fclose(Infp); Outfp=fopen("C:\\TC\\Output\\ans1.txt","wt"); fprintf(Outfp,"%d %d %ld\n",Start,End,rec[5].Key1); fclose(Outfp); }