Computer Programming Contest Preparation

ToolBox - Source for: 126/12640/c.c



/home/toolbox/public_html/solutions/126/12640/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 <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-25
   19  * Purpose:
   20  * Problem: 482
   21  */
   22 
   23 /*
   24  * This template reads lines of data at a time until end of file.
   25  */
   26 
   27 #define MAX_LINE 50
   28 #define MAX_NUMBERS 1000000
   29 
   30 
   31 int  numCases;
   32 char line[MAX_NUMBERS];
   33 int  numbers[MAX_NUMBERS];
   34 char values[MAX_NUMBERS][MAX_LINE];
   35 int  numCnt;
   36 
   37 
   38 void init()
   39 {
   40     /* FUNCTION init */
   41 } /* FUNCTION init */
   42 
   43 void dump()
   44 {
   45     /* FUNCTION dump */
   46 } /* FUNCTION dump */
   47 
   48 int getInput()
   49 {
   50     /* FUNCTION getInput */
   51 
   52     /* get first line of input */
   53     fgets(line, sizeof(line), stdin);
   54     endOfFile = (2 > strlen(line));
   55     line[strlen(line) - 1] = 0;
   56     return endOfFile;
   57 } /* FUNCTION getInput */
   58 
   59 char *tmp;
   60 char *token;
   61 int cnt;
   62 int i;
   63 /* extract the numbers */
   64 tmp = line;
   65 numCnt = 1;
   66 token = strtok(tmp, " ");
   67 while (NULL != token)
   68     {
   69         /* while something left in string */
   70         sscanf(token, " %d ", &numbers[numCnt]);
   71         DEBUG printf("[%s] %d: %d\n", token, numCnt, numbers[numCnt]);
   72         numCnt++;
   73         token = strtok(NULL, " ");
   74     } /* while something left in string */
   75 /* load values */
   76 fgets(line, sizeof(line), stdin);
   77 line[strlen(line) - 1] = 0;
   78 tmp = line;
   79 DEBUG printf("line[%s]\n", tmp);
   80 token = strtok(tmp, " ");
   81 DEBUG printf("token [%s]\n", token);
   82 for (i=1; i<numCnt; i++)
   83     {
   84         /* for */
   85         sscanf(token, "%s", values[numbers[i]]);
   86         DEBUG printf("%d -- %d: token [%s]\n", i, numbers[i], values[numbers[i]]);
   87         token = strtok(NULL, " ");
   88     } /* for */
   89 fgets(line, sizeof(line), stdin);
   90 line[strlen(line) - 1] = 0;
   91 DEBUG printf("skip line[%s]\n", line);
   92 
   93 void process()
   94 {
   95     /* FUNCTION process */
   96     int i;
   97 
   98     for (i=1; i<numCnt; i++)
   99         {
  100             /* for */
  101             printf("%s\n", values[i]);
  102         } /* for */
  103 } /* FUNCTION process */
  104 
  105 int main()
  106 {
  107     /* main */
  108     int i;
  109 
  110     init();
  111     endOfFile = getInput();
  112     while (! endOfFile)
  113         {
  114             /* while */
  115             process();
  116             endOfFile = getInput();
  117         } /* while */
  118 
  119     return EXIT_SUCCESS;
  120 } /* main */
  121