Computer Programming Contest Preparation

ToolBox - Source for: 126/12667/a.c



/home/toolbox/public_html/solutions/126/12667/a.c
    1 #include <stdio.h>
    2 #include <string.h>
    3 #include <sys/types.h>
    4 #include <sys/stat.h>
    5 #include <fcntl.h>
    6 #include <stdlib.h>
    7 #include <math.h>
    8 #include <stdint.h>
    9 #include <ctype.h>
   10 
   11 #define TRUE  (1 == 1)
   12 #define FALSE (1 != 1)
   13 
   14 #define DEBUG if (FALSE)
   15 
   16 /* fprintf(stderr, "functionName: message", varslist); */
   17 
   18 /*
   19  *  Author: Isaac Traxler
   20  *    Date:
   21  * Purpose: fun
   22  * Problem:
   23  */
   24 
   25 /*
   26  * This template reads data a specified number of times.
   27  */
   28 
   29 #define MAX_teamCnt 102
   30 #define MAX_problemCnt 13
   31 
   32 int problemCnt;
   33 int teamCnt;
   34 int submissions;
   35 int mat[MAX_teamCnt][MAX_problemCnt];
   36 int solutionTime;
   37 int id;
   38 char prob[2];
   39 char result[4];
   40 int problem;
   41 
   42 void init()
   43 {
   44     /* FUNCTION init */
   45     int i;
   46     int j;
   47 
   48     scanf(" %d %d %d ", &problemCnt, &teamCnt, &submissions );
   49     /* we will use team 0 to track last to solve */
   50     for (i=0; teamCnt>=i; i++)
   51         {
   52             /* for each team */
   53             for (j=0; problemCnt>j; j++)
   54                 {
   55                     /* for each problem */
   56                     mat[i][j] = 0;
   57                 } /* for each problem */
   58         } /* for each team */
   59 
   60 } /* FUNCTION init */
   61 
   62 void dump()
   63 {
   64     /* FUNCTION dump */
   65     int i;
   66     int j;
   67 
   68     for (i=0; teamCnt>=i; i++)
   69         {
   70             /* for i */
   71             printf("%3d: ", i);
   72             for (j=0; problemCnt>j; j++)
   73                 {
   74                     /* for j */
   75                     printf(" %3d", mat[i][j]);
   76                 } /* for j */
   77             printf("\n");
   78         } /* for i */
   79 } /* FUNCTION dump */
   80 
   81 void getInput()
   82 {
   83     /* FUNCTION getInput */
   84     scanf(" %d %d %s %s ", &solutionTime, &id, prob, result);
   85     problem = prob[0] - 'A';
   86 } /* FUNCTION getInput */
   87 
   88 void process()
   89 {
   90     /* FUNCTION process */
   91     int i;
   92 
   93     if ('Y' == result[0])
   94         {
   95             /* solution found */
   96             if (0 == mat[id][problem])
   97                 {
   98                     /* first time this team has solved this problem */
   99                     DEBUG printf("Team %d solved problem %d at time %d\n", id, problem, solutionTime);
  100                     mat[id][problem] = solutionTime;
  101                     mat[0][problem] = id; /* i is the last team to solve this problem */
  102                 } /* first time this team has solved this problem */
  103         } /* solution found */
  104 } /* FUNCTION process */
  105 
  106 int main()
  107 {
  108     /* main */
  109     int i;
  110     char let = 'A';
  111 
  112     init();
  113     for (i=0; i<submissions; i++)
  114         {
  115             /* while */
  116             getInput();
  117             process();
  118         } /* while */
  119     DEBUG dump();
  120     for (i=0; problemCnt>i; i++)
  121         {
  122             /* output resilts for each problem */
  123             printf("%c ", let);
  124             let++;
  125             if (0 == mat[0][i])
  126                 {
  127                     /* nobody solved this problem */
  128                     printf("- -\n");
  129                 } /* nobody solved this problem */
  130             else
  131                 {
  132                     /* print last blood */
  133                     printf("%d %d\n", mat[mat[0][i]][i], mat[0][i]);
  134                 } /* print last blood */
  135         } /* output resilts for each problem */
  136 
  137     return EXIT_SUCCESS;
  138 } /* main */
  139 
  140