Computer Programming Contest Preparation

ToolBox - Source for: 7/706/matt.c



/home/toolbox/public_html/solutions/7/706/matt.c
    1 #include <stdio.h>
    2 #include <stdlib.h>
    3 #include <string.h>
    4 
    5 /*
    6  *  Author: Matthew Eastman <meastman@cct.lsu.edu>
    7  *    Date: 2006-09-05
    8  * Purpose: Contest practice
    9  * Problem: 706 - LC-Display <http://isaac.lsu.edu/udv/v7/706.html>
   10  */
   11 
   12 #define FALSE 0
   13 #define TRUE  1
   14 
   15 const char lcd[10][8] =
   16 {
   17     "-|| ||-", /* 0 */
   18     "  |  | ", /* 1 */
   19     "- |-| -", /* 2 */
   20     "- |- |-", /* 3 */
   21     " ||- | ", /* 4 */
   22     "-| - |-", /* 5 */
   23     "-| -||-", /* 6 */
   24     "- |  | ", /* 7 */
   25     "-||-||-", /* 8 */
   26     "-||- |-", /* 9 */
   27 };
   28 
   29 int count;
   30 int display;
   31 char buff[12];
   32 
   33 int getInput(void)
   34 {
   35     int status = FALSE;
   36 
   37     if ((2 == scanf(" %d %d ", &count, &display)) && (0 < count))
   38         {
   39             status = TRUE;
   40             sprintf(buff, "%d", display);
   41         }
   42 
   43     /* printf("*** status is %d\n", status); */
   44 
   45     return status;
   46 }
   47 
   48 void solveProblem(void)
   49 {
   50     /* printf("Count: %d, Buff: \"%s\"\n", count, buff); */
   51     int i, j, k;
   52 
   53     /* top row */
   54     for (i = 0; buff[i]; i++)
   55         {
   56             printf(" ");
   57             for (j = 0; j < count; j++)
   58                 {
   59                     printf("%c", lcd[buff[i] - '0'][0]);
   60                 }
   61             printf(" ");
   62 
   63             if (buff[i + 1])
   64                 printf(" ");
   65         }
   66     printf("\n");
   67 
   68     /* second row */
   69     for (i = 0; i < count; i++)
   70         {
   71             for (j = 0; buff[j]; j++)
   72                 {
   73                     printf("%c", lcd[buff[j] - '0'][1]);
   74                     for (k = 0; k < count; k++)
   75                         printf(" ");
   76                     printf("%c", lcd[buff[j] - '0'][2]);
   77 
   78                     if (buff[j + 1])
   79                         printf(" ");
   80                 }
   81 
   82             printf("\n");
   83         }
   84 
   85     /* middle row */
   86     for (i = 0; buff[i]; i++)
   87         {
   88             printf(" ");
   89             for (j = 0; j < count; j++)
   90                 {
   91                     printf("%c", lcd[buff[i] - '0'][3]);
   92                 }
   93             printf(" ");
   94 
   95             if (buff[i + 1])
   96                 printf(" ");
   97         }
   98     printf("\n");
   99 
  100     /* 4th row */
  101     for (i = 0; i < count; i++)
  102         {
  103             for (j = 0; buff[j]; j++)
  104                 {
  105                     printf("%c", lcd[buff[j] - '0'][4]);
  106                     for (k = 0; k < count; k++)
  107                         printf(" ");
  108                     printf("%c", lcd[buff[j] - '0'][5]);
  109 
  110                     if (buff[j + 1])
  111                         printf(" ");
  112                 }
  113 
  114             printf("\n");
  115         }
  116 
  117     /* bottom row */
  118     for (i = 0; buff[i]; i++)
  119         {
  120             printf(" ");
  121             for (j = 0; j < count; j++)
  122                 {
  123                     printf("%c", lcd[buff[i] - '0'][6]);
  124                 }
  125             printf(" ");
  126 
  127             if (buff[i + 1])
  128                 printf(" ");
  129         }
  130     printf("\n");
  131 
  132     printf("\n");
  133 }
  134 
  135 int main()
  136 {
  137     while (getInput())
  138         {
  139             solveProblem();
  140         }
  141 
  142     return EXIT_SUCCESS;
  143 }
  144 
  145