Computer Programming Contest Preparation

ToolBox - Source for: 117/11716/a.c



/home/toolbox/public_html/solutions/117/11716/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: 2023-11-14
   21  * Purpose: fun
   22  * Problem: 11716 - Digital Fortress
   23  */
   24 
   25 /*
   26  * This template reads data a specified number of times.
   27  */
   28 
   29 #define MAX_LINE 10005
   30 
   31 int numberOfTimes;
   32 char line[MAX_LINE];
   33 
   34 void init()
   35 {
   36     /* FUNCTION init */
   37     scanf("%d ", &numberOfTimes);
   38 } /* FUNCTION init */
   39 
   40 void dump()
   41 {
   42     /* FUNCTION dump */
   43 } /* FUNCTION dump */
   44 
   45 void getInput()
   46 {
   47     /* FUNCTION getInput */
   48     fgets(line, MAX_LINE, stdin);
   49     line[strlen(line)-1] = 0;
   50 } /* FUNCTION getInput */
   51 
   52 void process()
   53 {
   54     /* FUNCTION process */
   55     int tlen;
   56     int tmp;
   57     int i;
   58     int j;
   59 
   60     tlen = strlen(line);
   61     tmp = sqrt(tlen);
   62     /* is it a square */
   63     if ((tmp * tmp) != tlen)
   64         {
   65             /* not a square */
   66             printf("INVALID\n");
   67         } /* not a square */
   68     else
   69         {
   70             /* process string */
   71             for (j=0; j<tmp; j++)
   72                 {
   73                     /* j loop */
   74                     for (i=j; i<tlen; i = i + tmp)
   75                         {
   76                             /* i loop */
   77                             printf("%c", line[i]);
   78                         } /* i loop */
   79                 } /* j loop */
   80             printf("\n");
   81         } /* process string */
   82 } /* FUNCTION process */
   83 
   84 int main()
   85 {
   86     /* main */
   87     int i;
   88 
   89     init();
   90     for (i=0; i<numberOfTimes; i++)
   91         {
   92             /* while */
   93             getInput();
   94             process();
   95         } /* while */
   96 
   97     return EXIT_SUCCESS;
   98 } /* main */
   99 
  100