Computer Programming Contest Preparation

ToolBox - Source for: 101/10127/a.c



/home/toolbox/public_html/solutions/101/10127/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 
   10 #define TRUE  (1 == 1)
   11 #define FALSE (1 != 1)
   12 
   13 #define DEBUG if (FALSE)
   14 
   15 /*
   16  *  Author:
   17  *    Date:
   18  * Purpose:
   19  * Problem:
   20  */
   21 
   22 /*
   23  * This template reads data until a terminating value is reached.
   24  */
   25 
   26 int num;
   27 
   28 void init()
   29 {
   30     /* FUNCTION init */
   31 } /* FUNCTION init */
   32 
   33 void dump()
   34 {
   35     /* FUNCTION dump */
   36 } /* FUNCTION dump */
   37 
   38 int getInput()
   39 {
   40     /* FUNCTION getInput */
   41     int dataReadFlag;
   42 
   43     dataReadFlag = 1 == scanf("%d ", &num);
   44     return (dataReadFlag);
   45 } /* FUNCTION getInput */
   46 
   47 void process()
   48 {
   49     /* FUNCTION process */
   50     int cnt = 1;
   51     int ones = 1;
   52 
   53     while (0 < ones)
   54         {
   55             /* while */
   56             while (num > ones)
   57                 {
   58                     /* while */
   59                     ones = ones * 10 + 1;
   60                     cnt++;
   61                 } /* while */
   62             ones = ones % num;
   63         } /* while */
   64 
   65     printf("%d\n", cnt);
   66 } /* FUNCTION process */
   67 
   68 int main ()
   69 {
   70     /* main */
   71     int moreToDo;
   72 
   73     init();
   74     moreToDo = getInput();
   75     while (moreToDo)
   76         {
   77             /* while */
   78             process();
   79             moreToDo = getInput();
   80         } /* while */
   81 
   82     return EXIT_SUCCESS;
   83 } /* main */
   84