Computer Programming Contest Preparation

ToolBox - Source for: 108/10878/a.c



/home/toolbox/public_html/solutions/108/10878/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 #define MAX_LINE 257
   16 
   17 /*
   18  *  Author: Isaac Traxler
   19  *    Date: 3017-01-18
   20  * Purpose: fun
   21  * Problem: 10878
   22  */
   23 
   24 /*
   25  * This template reads lines of data at a time until end of file.
   26  */
   27 
   28 char line[MAX_LINE];
   29 
   30 /*   6310000
   31  *   4268421
   32  *   -------
   33  * A 1000001  65
   34  * b 1100010  98
   35  * c 1100011  99
   36  * d 1100100 100
   37  * e 1100101 101
   38  * f 1100110 102
   39  * g 1100111 103
   40  * h 1101000 104
   41  * i 1101001 105
   42  * j 1101010 106
   43  * k 1101011 107
   44  * l 1101100 108
   45  * m 1101101 109
   46  * n 1101110 110
   47  * o 1101111 111
   48  * p 1110000 112
   49  * q 1110001 113
   50  * r 1110010 114
   51  * s 1110011 115
   52  * t 1110100 116
   53  * u 1110101 117
   54  * v 1110110 118
   55  * w 1110111 119
   56  * x 1111000 120
   57  * y 1111001 121
   58  * z 1111010 122
   59  *   0100000  32
   60  * . 0101110  46
   61  *NL 0001010  10
   62  */
   63 
   64 void init()
   65 {
   66     /* FUNCTION init */
   67 } /* FUNCTION init */
   68 
   69 void dump()
   70 {
   71     /* FUNCTION dump */
   72 } /* FUNCTION dump */
   73 
   74 int getInput()
   75 {
   76     /* FUNCTION getInput */
   77     int dataReadFlag;
   78 
   79     fgets(line, MAX_LINE, stdin);
   80     if (feof(stdin))
   81         dataReadFlag = FALSE;
   82     else
   83         {
   84             /* something to read */
   85             dataReadFlag = ('|' == line[0]);
   86             /*
   87             line[strlen(line)-1] = 0;
   88             */
   89         } /* something to read */
   90     return (dataReadFlag);
   91 } /* FUNCTION getInput */
   92 
   93 int hole(char x)
   94 {
   95     /* FUNCTION hole */
   96     int toReturn;
   97 
   98     if ('o' == x)
   99         toReturn = 1;
  100     else
  101         toReturn = 0;
  102     return toReturn;
  103 } /* FUNCTION hole */
  104 
  105 void process()
  106 {
  107     /* FUNCTION process */
  108     int i;
  109     int tot;
  110 
  111     tot = hole(line[2])*64 +
  112           hole(line[3])*32 +
  113           hole(line[4])*16 +
  114           hole(line[5])*8 +
  115           hole(line[7])*4 +
  116           hole(line[8])*2 +
  117           hole(line[9]);
  118     if (13 == tot)
  119         {
  120             /* put in new line */
  121             printf("\n");
  122         } /* put in new line */
  123     else
  124         {
  125             /* other chars */
  126             printf("%c", tot);
  127         } /* other chars */
  128 
  129 } /* FUNCTION process */
  130 
  131 int main()
  132 {
  133     /* main */
  134     int moreToDo;
  135 
  136     init();
  137     /* skip first line */
  138     moreToDo = getInput();
  139     /* get first real line */
  140     moreToDo = getInput();
  141     while (moreToDo)
  142         {
  143             /* while */
  144             process();
  145             moreToDo = getInput();
  146         } /* while */
  147 
  148     return EXIT_SUCCESS;
  149 } /* main */
  150