Computer Programming Contest Preparation

ToolBox - Source for: 111/11192/a.c



/home/toolbox/public_html/solutions/111/11192/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 <stdint.h>
    7 #include <math.h>
    8 #include <stdlib.h>
    9 #include <ctype.h>
   10 
   11 #define TRUE  (1 == 1)
   12 #define FALSE (1 != 1)
   13 
   14 #define DEBUG if (FALSE)
   15 
   16 /*
   17  *  Author: Isaac Traxler
   18  *    Date: 2021-12-7
   19  * Purpose: fun
   20  * Problem: 11192 - Group Reverse
   21  */
   22 
   23 /*
   24  * This template reads data until a terminating value is reached.
   25  */
   26 
   27 #define MAX_LINE 111
   28 
   29 char line[MAX_LINE];
   30 int groups;
   31 int rev;
   32 
   33 void init()
   34 {
   35     /* FUNCTION init */
   36 } /* FUNCTION init */
   37 
   38 void dump()
   39 {
   40     /* FUNCTION dump */
   41 } /* FUNCTION dump */
   42 
   43 int getInput()
   44 {
   45     /* FUNCTION getInput */
   46     int dataReadFlag;
   47 
   48     scanf(" %d ", &groups);
   49     dataReadFlag = (0 != groups);
   50     if (dataReadFlag)
   51         {
   52             scanf(" %s ", line);
   53         }
   54     return (dataReadFlag);
   55 } /* FUNCTION getInput */
   56 
   57 void process()
   58 {
   59     /* FUNCTION process */
   60     int i;
   61     int j;
   62     int slen;
   63 
   64     slen = strlen(line);
   65     rev = slen / groups;
   66     for (i=0; slen>i; i=i+rev)
   67         {
   68             /* for each group */
   69             for (j=0; rev>j; j++)
   70                 {
   71                     /* each item in a group */
   72                     printf("%c", line[i+rev-1-j]);
   73                 } /* each item in a group */
   74         } /* for each group */
   75     printf("\n");
   76 } /* FUNCTION process */
   77 
   78 int main()
   79 {
   80     /* main */
   81     int moreToDo;
   82 
   83     init();
   84     moreToDo = getInput();
   85     while (moreToDo)
   86         {
   87             /* while */
   88             process();
   89             moreToDo = getInput();
   90         } /* while */
   91 
   92     return EXIT_SUCCESS;
   93 } /* main */
   94