Computer Programming Contest Preparation

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



/home/toolbox/public_html/solutions/113/11340/c.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 256
   29 #define MAX_LINE 10009
   30 
   31 int  numberOfTimes;
   32 int  letCnt;
   33 int  pay[MAX_LETTERS];
   34 int  lineCnt;
   35 char line[MAX_LINE];
   36 int  total;
   37 
   38 void init()
   39 {
   40     /* FUNCTION init */
   41     scanf("%d ", &numberOfTimes);
   42 } /* FUNCTION init */
   43 
   44 void dump()
   45 {
   46     /* FUNCTION dump */
   47 } /* FUNCTION dump */
   48 
   49 void caseReset()
   50 {
   51     /* FUNCTION caseReset */
   52     int i;
   53 
   54     total = 0;
   55     for (i=0; MAX_LETTERS>i; i++)
   56         {
   57             /* for */
   58             pay[i] = 0;
   59         } /* for */
   60 
   61 } /* FUNCTION caseReset */
   62 
   63 void getInput()
   64 {
   65     /* FUNCTION getInput */
   66     int i;
   67     char c;
   68     int amount;
   69 
   70     caseReset();
   71     scanf(" %d ", &letCnt);
   72     for (i=0; i<letCnt; i++)
   73         {
   74             /* for */
   75             scanf("%c %d ", &c, &amount);
   76             pay[c] = amount;
   77         } /* for */
   78 } /* FUNCTION getInput */
   79 
   80 int processLine()
   81 {
   82     /* FUNCTION processLine */
   83     int i;
   84     int tot = 0;
   85 
   86     for (i=0; strlen(line)>i; i++)
   87         {
   88             /* for */
   89             tot = tot + pay[line[i]];
   90         } /* for */
   91     DEBUG printf("%d [%s]\n", tot, line);
   92     return tot;
   93 } /* FUNCTION processLine */
   94 
   95 void process()
   96 {
   97     /* FUNCTION process */
   98     int i;
   99     int cents;
  100     int dollars;
  101 
  102     scanf(" %d ", &lineCnt);
  103     for (i=0; i<lineCnt; i++)
  104         {
  105             /* for */
  106             scanf(" %[^\n]", line);
  107             total = total + processLine();
  108             DEBUG printf("%d: [%s]\n", strlen(line), line);
  109         } /* for */
  110     cents = total % 100;
  111     dollars = total / 100;
  112     printf("%d.%02d$\n", dollars, cents);
  113 } /* FUNCTION process */
  114 
  115 int main()
  116 {
  117     /* main */
  118     int i;
  119 
  120     init();
  121     for (i=0; i<numberOfTimes; i++)
  122         {
  123             /* while */
  124             getInput();
  125             process();
  126         } /* while */
  127 
  128     return EXIT_SUCCESS;
  129 } /* main */
  130 
  131