Computer Programming Contest Preparation

ToolBox - Source for: 113/11340/b.c



/home/toolbox/public_html/solutions/113/11340/b.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 <stdlib.h>
    7 #include <math.h>
    8 #include <stdint.h>
    9 
   10 #define TRUE  (1 == 1)
   11 #define FALSE (1 != 1)
   12 
   13 #define DEBUG if (FALSE)
   14 
   15 /* fprintf(stderr, "functionName: message", varslist); */
   16 
   17 /*
   18  *  Author: Isaac Traxler
   19  *    Date: 2015-03-22
   20  * Purpose:
   21  * Problem: 11340
   22  */
   23 
   24 /*
   25  * This template reads data a specified number of times.
   26  */
   27 
   28 #define MAX_LETTERS 101
   29 #define MAX_LINE 10009
   30 
   31 int  numberOfTimes;
   32 int  letCnt;
   33 char letters[MAX_LETTERS];
   34 int  pay[MAX_LETTERS];
   35 int  lineCnt;
   36 char line[MAX_LINE];
   37 int  total;
   38 
   39 void init()
   40 {
   41     /* FUNCTION init */
   42     scanf("%d ", &numberOfTimes);
   43 } /* FUNCTION init */
   44 
   45 void dump()
   46 {
   47     /* FUNCTION dump */
   48     int i;
   49 
   50     for (i=0; i<letCnt; i++)
   51         {
   52             /* for */
   53             printf("let[%d] = %c    pay[%d] = %d\n", i, letters[i], i, pay[i]);
   54         } /* for */
   55 } /* FUNCTION dump */
   56 
   57 void getInput()
   58 {
   59     /* FUNCTION getInput */
   60     int i;
   61 
   62     scanf(" %d ", &letCnt);
   63     for (i=0; i<letCnt; i++)
   64         {
   65             /* for */
   66             scanf("%c %d ", &letters[i], &pay[i]);
   67         } /* for */
   68 } /* FUNCTION getInput */
   69 
   70 int lookupValue(char c)
   71 {
   72     /* FUNCTION lookupValue */
   73     int i;
   74     int ret = 0;
   75 
   76     for (i=0; i<letCnt; i++)
   77         {
   78             /* for */
   79             if (c == letters[i])
   80                 {
   81                     /* match */
   82                     ret = pay[i];
   83                     i = letCnt;
   84                 } /* match */
   85         } /* for */
   86     return ret;
   87 } /* FUNCTION lookupValue */
   88 
   89 int processLine()
   90 {
   91     /* FUNCTION processLine */
   92     int i;
   93     int tot = 0;
   94 
   95     for (i=0; strlen(line)>i; i++)
   96         {
   97             /* for */
   98             tot = tot + lookupValue(line[i]);
   99         } /* for */
  100     DEBUG printf("%d [%s]\n", tot, line);
  101     return tot;
  102 } /* FUNCTION processLine */
  103 
  104 void process()
  105 {
  106     /* FUNCTION process */
  107     int i;
  108     int cents;
  109     int dollars;
  110 
  111     total = 0;
  112     scanf(" %d ", &lineCnt);
  113     for (i=0; i<lineCnt; i++)
  114         {
  115             /* for */
  116             scanf(" %[^\n]", line);
  117             total = total + processLine();
  118             DEBUG printf("%d: [%s]\n", strlen(line), line);
  119         } /* for */
  120     cents = total % 100;
  121     dollars = total / 100;
  122     printf("%d.%02d$\n", dollars, cents);
  123 } /* FUNCTION process */
  124 
  125 int main()
  126 {
  127     /* main */
  128     int i;
  129 
  130     init();
  131     for (i=0; i<numberOfTimes; i++)
  132         {
  133             /* while */
  134             getInput();
  135             DEBUG dump();
  136             process();
  137         } /* while */
  138 
  139     return EXIT_SUCCESS;
  140 } /* main */
  141 
  142