Computer Programming Contest Preparation

ToolBox - Source for: 125/12592/a.c



/home/toolbox/public_html/solutions/125/12592/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 <stdlib.h>
    7 #include <math.h>
    8 #include <stdint.h>
    9 #include <ctype.h>
   10 
   11 #define TRUE  (1 == 1)
   12 #define FALSE (1 != 1)
   13 
   14 #define DEBUG if (FALSE)
   15 
   16 /* fprintf(stderr, "functionName: message", varslist); */
   17 
   18 /*
   19  *  Author: Isaac Traxler
   20  *    Date: 2021-10-18
   21  * Purpose: fun
   22  * Problem: 12592
   23  */
   24 
   25 /*
   26  * This template reads data a specified number of times.
   27  */
   28 
   29 #define MAX_LINE 132
   30 #define MAX_SLOGANS 22
   31 
   32 int numberOfSlogans;
   33 int numberOfQueries;
   34 char slogans[MAX_SLOGANS][MAX_LINE];
   35 char responses[MAX_SLOGANS][MAX_LINE];
   36 char query[MAX_LINE];
   37 
   38 void init()
   39 {
   40     /* FUNCTION init */
   41     int i;
   42 
   43     scanf(" %d ", &numberOfSlogans);
   44     for (i=0; numberOfSlogans>i; i++)
   45         {
   46             /* get each pair of lines */
   47             fgets(slogans[i], MAX_LINE, stdin);
   48             fgets(responses[i], MAX_LINE, stdin);
   49         } /* get each pair of lines */
   50     scanf(" %d ", &numberOfQueries);
   51 } /* FUNCTION init */
   52 
   53 void dump()
   54 {
   55     /* FUNCTION dump */
   56 } /* FUNCTION dump */
   57 
   58 void getInput()
   59 {
   60     /* FUNCTION getInput */
   61     fgets(query, MAX_LINE, stdin);
   62 } /* FUNCTION getInput */
   63 
   64 void process()
   65 {
   66     /* FUNCTION process */
   67     int i;
   68 
   69     for (i=0; numberOfSlogans>i; i++)
   70         {
   71             /* for */
   72             if (0 == strcmp(query, slogans[i]))
   73                 {
   74                     /* match found */
   75                     printf("%s", responses[i]);
   76                     i = numberOfSlogans + 1;
   77                 } /* match found */
   78         } /* for */
   79 } /* FUNCTION process */
   80 
   81 int main()
   82 {
   83     /* main */
   84     int i;
   85 
   86     init();
   87     for (i=0; i<numberOfQueries; i++)
   88         {
   89             /* while */
   90             getInput();
   91             process();
   92         } /* while */
   93 
   94     return EXIT_SUCCESS;
   95 } /* main */
   96 
   97