Computer Programming Contest Preparation

ToolBox - Source for: 100/10082/a.c



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