Computer Programming Contest Preparation

ToolBox - Source for: 109/10921/a.c



/home/toolbox/public_html/solutions/109/10921/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 /*
   17  *  Author: Isaac Traxler
   18  *    Date: 2015-03-15
   19  * Purpose:
   20  * Problem: 10921
   21  */
   22 
   23 /*
   24  * This template reads lines of data at a time until end of file.
   25  */
   26 
   27 #define MAX_LINE 257
   28 
   29 char line[MAX_LINE];
   30 
   31 void init()
   32 {
   33     /* FUNCTION init */
   34 } /* FUNCTION init */
   35 
   36 void dump()
   37 {
   38     /* FUNCTION dump */
   39 } /* FUNCTION dump */
   40 
   41 int getInput()
   42 {
   43     /* FUNCTION getInput */
   44     int dataReadFlag;
   45 
   46     fgets(line, MAX_LINE, stdin);
   47     if (feof(stdin))
   48         dataReadFlag = FALSE;
   49     else
   50         {
   51             /* something to read */
   52             dataReadFlag = TRUE;
   53             line[strlen(line)-1] = 0;
   54         } /* something to read */
   55     return (dataReadFlag);
   56 } /* FUNCTION getInput */
   57 
   58 void process()
   59 {
   60     /* FUNCTION process */
   61     int i;
   62 
   63     for (i=0; i<strlen(line); i++)
   64         {
   65             /* for */
   66             switch (line[i])
   67                 {
   68                     /* switch */
   69                 case 'A':
   70                 case 'B':
   71                 case 'C':
   72                     line[i] = '2';
   73                     break;
   74                 case 'D':
   75                 case 'E':
   76                 case 'F':
   77                     line[i] = '3';
   78                     break;
   79                 case 'G':
   80                 case 'H':
   81                 case 'I':
   82                     line[i] = '4';
   83                     break;
   84                 case 'J':
   85                 case 'K':
   86                 case 'L':
   87                     line[i] = '5';
   88                     break;
   89                 case 'M':
   90                 case 'N':
   91                 case 'O':
   92                     line[i] = '6';
   93                     break;
   94                 case 'P':
   95                 case 'Q':
   96                 case 'R':
   97                 case 'S':
   98                     line[i] = '7';
   99                     break;
  100                 case 'T':
  101                 case 'U':
  102                 case 'V':
  103                     line[i] = '8';
  104                     break;
  105                 case 'W':
  106                 case 'X':
  107                 case 'Y':
  108                 case 'Z':
  109                     line[i] = '9';
  110                     break;
  111                 } /* switch */
  112         } /* for */
  113     printf("%s\n", line);
  114 } /* FUNCTION process */
  115 
  116 int main()
  117 {
  118     /* main */
  119     int moreToDo;
  120 
  121     init();
  122     moreToDo = getInput();
  123     while (moreToDo)
  124         {
  125             /* while */
  126             process();
  127             moreToDo = getInput();
  128         } /* while */
  129 
  130     return EXIT_SUCCESS;
  131 } /* main */
  132