Computer Programming Contest Preparation

ToolBox - Source for: 4/483/b.c



/home/toolbox/public_html/solutions/4/483/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 <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 100000
   16 
   17 /*
   18  *  Author: Isaac Traxler
   19  *    Date: 2015-02-04
   20  * Purpose: fun
   21  * Problem: 483
   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 int i;
   30 int llen;
   31 
   32 void dump()
   33 {
   34     /* FUNCTION dump */
   35 } /* FUNCTION dump */
   36 
   37 int getInput()
   38 {
   39     /* FUNCTION getInput */
   40     int dataReadFlag;
   41 
   42     fgets(line, MAX_LINE, stdin);
   43     if (feof(stdin))
   44         dataReadFlag = FALSE;
   45     else
   46         {
   47             /* something to read */
   48             dataReadFlag = TRUE;
   49             line[strlen(line)-1] = 0;
   50             llen = strlen(line);
   51             DEBUG printf("line: [%s]\n", line);
   52         } /* something to read */
   53     return (dataReadFlag);
   54 } /* FUNCTION getInput */
   55 
   56 void doWhiteSpace()
   57 {
   58     /* FUNCTION doWhiteSpace */
   59     while (isspace(line[i]))
   60         {
   61             /* while */
   62             if ('\n' != line[i])
   63                 {
   64                     printf("%c", line[i]);
   65                 }
   66             i++;
   67         } /* while */
   68 } /* FUNCTION doWhiteSpace */
   69 
   70 void doText()
   71 {
   72     /* FUNCTION doText */
   73     int b = 0;
   74     char buf[MAX_LINE];
   75 
   76     while ((i<llen) && (!isspace(line[i])))
   77         {
   78             /* while */
   79             buf[b++] = line[i++];
   80         } /* while */
   81     b--;
   82     while (-1<b)
   83         {
   84             printf("%c", buf[b--]);
   85         }
   86 } /* FUNCTION doText */
   87 
   88 void process()
   89 {
   90     /* FUNCTION process */
   91 
   92     for (i=0; i<strlen(line); )
   93         {
   94             /* for */
   95             doWhiteSpace();
   96             doText();
   97         } /* for */
   98 } /* FUNCTION process */
   99 
  100 int main()
  101 {
  102     /* main */
  103     int moreToDo;
  104     int first = TRUE;
  105 
  106     moreToDo = getInput();
  107     while (moreToDo)
  108         {
  109             /* while */
  110             if (! first)
  111                 {
  112                     printf("\n");
  113                 }
  114             process();
  115             moreToDo = getInput();
  116             first = FALSE;
  117         } /* while */
  118 
  119     return EXIT_SUCCESS;
  120 } /* main */
  121