home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume17 / contest-prog / part03 / score.c < prev   
C/C++ Source or Header  |  1989-02-06  |  3KB  |  131 lines

  1. #define CURVERS 21
  2. #define HOURS 4
  3. #include <stdio.h>
  4. #include <sys/types.h>
  5. #ifdef sequent
  6. #include <sys/time.h>
  7. #else
  8. #include <time.h>
  9. #endif
  10. int prob,team;
  11. char *let[4] = {
  12.     "   ","beg","int","adv"};
  13. int category[31];
  14.  
  15. main()
  16. {
  17.     char *malloc();
  18.     char *end;
  19.     FILE *fopen(), *fp ;
  20.     int sus,finish;
  21.     long version,starttime;
  22.     char *teamnames[31], *strcpy();
  23.     time_t ct,ct1;
  24.     long time();
  25.     int solvedat[31][19];
  26.     int penal[31],nfail[31],nworked[31];
  27.     int i,k;
  28.     long  endcontest;
  29.     char temp[81];
  30.  
  31.     for(team=1;team<=30;team++){
  32.         penal[team]=0;
  33.         nfail[team]=0;
  34.         nworked[team]=0;
  35.         teamnames[team]=(char *)0;
  36.         for(prob=1;prob<=18;prob++)solvedat[team][prob]=0;
  37.     }
  38.  
  39.     if ((fp= fopen(SCOREBOARD,"r")) == NULL) {
  40.         printf("Can not open scoreboard file [%s].\n",SCOREBOARD);
  41.         exit(1);
  42.     } 
  43.  
  44.     if ( fscanf(fp,"%d",&version) != 1) {
  45.         printf("Can not read version from scoreboard\n");
  46.         exit(2);
  47.     }
  48.     if (version!=CURVERS){
  49.         puts("an old version perhaps?");
  50.         exit(8);
  51.     }
  52.     for(i=1;i<=30;i++){
  53.         if( fscanf(fp,"%d%d%s",&team,&k,temp) != 3){
  54.             printf("%d%d%s\n",team,k,temp);exit(3);}
  55.             if(team==99)team=0;
  56.         if(k<0){
  57.         break;
  58.         }
  59.         else {
  60.         if(team==99)team=0;
  61.         category[team]=k;
  62.         teamnames[team]=malloc((unsigned)(strlen(temp)+2));
  63.         (void)strcpy(teamnames[team],temp);
  64.         }
  65.     }
  66.  
  67.     if(1!=fscanf(fp,"%ld",&starttime))exit(5) ;
  68.     endcontest=starttime+HOURS*3600;
  69.     ct = time((long *)0);
  70.     ct1=ct;
  71.     end="ends ";
  72.     if(ct>endcontest){ct=endcontest;end="ended";}
  73.  
  74.     while ( fscanf(fp,"%d %d %d %d",&sus,&team,&prob,&finish) == 4) {
  75.         if(team==99)team=0;
  76.         if (sus) { 
  77.             solvedat[team][prob]=finish;
  78.         }
  79.         else{
  80.             nfail[team]++;
  81.             penal[team] += 10;
  82.         }
  83.     }/*end of file*/
  84.  
  85.     (void) fclose(fp);
  86.  
  87.     for(team=1;team<=30;team++)
  88.         if(category[team])
  89.             for(k=prob=category[team]*6-5;prob<k+6;prob++)
  90.                 if(solvedat[team][prob])
  91.                 {
  92.                     penal[team] +=(solvedat[team][prob]-starttime)/60;
  93.                     nworked[team]++;
  94.                 }
  95.                 else
  96.                 {
  97.         penal[team] += (ct  - starttime)/60;
  98.                 }
  99.  
  100.     printf("\n                    the scoreboard \n\n");
  101.     printf("                %s\n",ctime((time_t *)&ct1));
  102.     printf("        contest began %s",ctime( (time_t *) &starttime));
  103.     printf("        contest %s %s\n",end,ctime( (time_t *) &endcontest));
  104.     printf(
  105.     "team class  #fail   penal  #solved   which           who\n");
  106.     for(i=3;i>=1;i--)
  107.     /*if(i!=2)*//*this line eliminates the intermediate category*/
  108.     {
  109.         puts("");
  110.         for(team=1;team<=15;team++)
  111.             if(category[team]==i)
  112.             {
  113.                 printf("%3d  %s %5d%11d     %d  "
  114.                     ,team,let[category[team]],nfail[team],
  115.                 penal[team],
  116.                 nworked[team]);
  117.                 if(category[team])
  118.                     for(k=prob=category[team]*6-5;prob<k+6;prob++)
  119.                         if(solvedat[team][prob])printf("%3d", prob);
  120.                         else printf("  .");
  121.                 if(teamnames[team]){
  122.                     (void)putchar(' ');
  123.                     (void)putchar(' ');
  124.                     puts(teamnames[team]);
  125.                 }
  126.                 else printf("\n");
  127.             }
  128.     }
  129.  
  130. }
  131.