Computer Programming Contest Preparation

ToolBox - Source for: 118/11879/a.c



/home/toolbox/public_html/solutions/118/11879/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 #define MAX_LINE 257
   17 
   18 /*
   19  *  Author: Isaac Traxler
   20  *    Date: 2021-12-6
   21  * Purpose: fun
   22  * Problem: 11879 - Multiple of 17
   23  */
   24 
   25 /*
   26  * This template reads lines of data at a time until end of file.
   27  */
   28 
   29 char line[MAX_LINE];
   30 
   31 void init()
   32 {
   33     /* FUNCTION init */
   34 } /* FUNCTION init */
   35 
   36 void dump()
   37 {
   38     /* FUNCTION dump */
   39 } /* FUNCTION dump */
   40 
   41 int getInput()
   42 {
   43     /* FUNCTION getInput */
   44     int dataReadFlag;
   45 
   46     fgets(line, MAX_LINE, stdin);
   47     line[strlen(line)-1] = 0;
   48     dataReadFlag = strcmp(line, "0");
   49     return (dataReadFlag);
   50 } /* FUNCTION getInput */
   51 
   52 void process()
   53 {
   54     /* FUNCTION process */
   55     int t = 0;
   56     int slen;
   57     int i;
   58 
   59     slen = strlen(line);
   60     for (i=0; slen>i; i++)
   61         {
   62             /* for */
   63             DEBUG printf("t %d (line %s) (line[%d] %c)\n", t, line, i, line[i]);
   64             t = ((t * 10) + (line[i] - '0')) % 17;
   65         } /* for */
   66     DEBUG printf("t %d (line %s) (line[%d] %c)\n", t, line, i, line[i]);
   67     if (0 == t)
   68         {
   69             /* divisible by 17 */
   70             printf("1\n");
   71         } /* divisible by 17 */
   72     else
   73         {
   74             /* not divisible by 17 */
   75             printf("0\n");
   76         } /* not divisible by 17 */
   77 } /* FUNCTION process */
   78 
   79 int main()
   80 {
   81     /* main */
   82     int moreToDo;
   83 
   84     init();
   85     moreToDo = getInput();
   86     while (moreToDo)
   87         {
   88             /* while */
   89             process();
   90             moreToDo = getInput();
   91         } /* while */
   92 
   93     return EXIT_SUCCESS;
   94 } /* main */
   95