Computer Programming Contest Preparation

ToolBox - Source for: 3/344/a.c



/home/toolbox/public_html/solutions/3/344/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 <stdint.h>
    7 #include <math.h>
    8 #include <stdlib.h>
    9 
   10 #define TRUE  (1 == 1)
   11 #define FALSE (1 != 1)
   12 
   13 #define DEBUG if (FALSE)
   14 
   15 /*
   16  *  Author: Isaac Traxler
   17  *    Date: 2021-01-11
   18  * Purpose: fun
   19  * Problem: 344 - Roman Digititis
   20  */
   21 
   22 /*
   23  * This template reads data until a terminating value is reached.
   24  */
   25 
   26 #define MAX_CACHE 102
   27 #define I 0
   28 #define V 1
   29 #define X 2
   30 #define L 3
   31 #define C 4
   32 
   33 int count[MAX_CACHE][5];
   34 int num;
   35 
   36 void init()
   37 {
   38     /* FUNCTION init */
   39     int i;
   40     int j;
   41 
   42     /* zero everything out */
   43     for (i=0; 101>i; i++)
   44         {
   45             /* for i */
   46             count[i][I] = 0;
   47             count[i][V] = 0;
   48             count[i][X] = 0;
   49             count[i][L] = 0;
   50             count[i][C] = 0;
   51         } /* for i */
   52     /* set first 10 (single digit numbers) */
   53     /* 1 - i    */ count[1][I] = 1;
   54     /* 2 - ii   */
   55     count[2][I] = 2;
   56     /* 3 - iii  */
   57     count[3][I] = 3;
   58     /* 4 - iv   */
   59     count[4][I] = 1;
   60     count[4][V] = 1;
   61     /* 5 - v    */
   62     count[5][V] = 1;
   63     /* 6 - vi   */
   64     count[6][I] = 1;
   65     count[6][V] = 1;
   66     /* 7 - vii  */
   67     count[7][I] = 2;
   68     count[7][V] = 1;
   69     /* 8 - viii */
   70     count[8][I] = 3;
   71     count[8][V] = 1;
   72     /* 9 - ix   */
   73     count[9][I] = 1;
   74     count[9][X] = 1;
   75 
   76     /* set each multiple of 10 */
   77     /* 10 - x    */
   78     count[10][X] = 1;
   79     /* 20 - xx   */
   80     count[20][X] = 2;
   81     /* 30 - xxx  */
   82     count[30][X] = 3;
   83     /* 40 - xl   */
   84     count[40][X] = 1;
   85     count[40][L] = 1;
   86     /* 50 - l    */
   87     count[50][L] = 1;
   88     /* 60 - lx   */
   89     count[60][X] = 1;
   90     count[60][L] = 1;
   91     /* 70 - lxx  */
   92     count[70][X] = 2;
   93     count[70][L] = 1;
   94     /* 80 - lxxx */
   95     count[80][X] = 3;
   96     count[80][L] = 1;
   97     /* 90 - xc   */
   98     count[90][X] = 1;
   99     count[90][C] = 1;
  100     /* 100 - c   */
  101     count[100][C] = 1;
  102     /* fill in gaps */
  103     for (i=0; 10>i; i++)
  104         {
  105             /* for i */
  106             for (j=10; 101>j; j=j+10)
  107                 {
  108                     /* for each j */
  109                     count[j+i][I] = count[i][I] + count[j][I];
  110                     count[j+i][V] = count[i][V] + count[j][V];
  111                     count[j+i][X] = count[i][X] + count[j][X];
  112                     count[j+i][L] = count[i][L] + count[j][L];
  113                     count[j+i][C] = count[i][C] + count[j][C];
  114                 } /* for each j */
  115         } /* for i */
  116     /* now do accumulations */
  117     for (i=1; 100>i; i++)
  118         {
  119             /* for i */
  120             j = i + 1;
  121             count[j][I] = count[j][I] + count[i][I];
  122             count[j][V] = count[j][V] + count[i][V];
  123             count[j][X] = count[j][X] + count[i][X];
  124             count[j][L] = count[j][L] + count[i][L];
  125             count[j][C] = count[j][C] + count[i][C];
  126         } /* for i */
  127 
  128 } /* FUNCTION init */
  129 
  130 void dump()
  131 {
  132     /* FUNCTION dump */
  133 } /* FUNCTION dump */
  134 
  135 int getInput()
  136 {
  137     /* FUNCTION getInput */
  138     int dataReadFlag;
  139 
  140     scanf(" %d ", &num);
  141     dataReadFlag = (0 < num);
  142     return (dataReadFlag);
  143 } /* FUNCTION getInput */
  144 
  145 void process()
  146 {
  147     /* FUNCTION process */
  148     printf("%d: %d i, %d v, %d x, %d l, %d c\n", num, count[num][I], count[num][V], count[num][X], count[num][L], count[num][C]);
  149 } /* FUNCTION process */
  150 
  151 int main()
  152 {
  153     /* main */
  154     int moreToDo;
  155 
  156     init();
  157     moreToDo = getInput();
  158     while (moreToDo)
  159         {
  160             /* while */
  161             process();
  162             moreToDo = getInput();
  163         } /* while */
  164 
  165     return EXIT_SUCCESS;
  166 } /* main */
  167