Computer Programming Contest Preparation

ToolBox - Source for: 107/10784/b.c



/home/toolbox/public_html/solutions/107/10784/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 #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-11-05
   19  * Purpose: fun
   20  * Problem: 10784 - Diagonal
   21  */
   22 
   23 /*
   24  * This template reads data until a terminating value is reached.
   25  */
   26 
   27 /*
   28  * 4   5   6   7   8   9  10  11  12  13  14  15  16
   29  * 2   5   9  14  20  27  35  44  54  65  77  90 104
   30  * ((n - 3) * n) / 2
   31  */
   32 
   33 #define MAX_CASE 1003
   34 
   35 long long list[MAX_CASE];
   36 long long num;
   37 int cnt;
   38 
   39 void init()
   40 {
   41     /* FUNCTION init */
   42     long long i;
   43 
   44     list[0] = 0;
   45     list[1] = 0;
   46     list[2] = 0;
   47     list[3] = 0;
   48     for (i=4; MAX_CASE>i; i++)
   49         {
   50             /* ncalculate each value */
   51             list[i] = ((i - 3) * i) / 2;
   52         } /* ncalculate each value */
   53     cnt = 1;
   54 } /* FUNCTION init */
   55 
   56 void dump()
   57 {
   58     /* FUNCTION dump */
   59 } /* FUNCTION dump */
   60 
   61 int getInput()
   62 {
   63     /* FUNCTION getInput */
   64     int dataReadFlag;
   65 
   66     scanf(" %lld ", &num);
   67     dataReadFlag = (0 != num);
   68     return (dataReadFlag);
   69 } /* FUNCTION getInput */
   70 
   71 void process()
   72 {
   73     /* FUNCTION process */
   74     int i;
   75 
   76     i = 4;
   77     while (num > list[i])
   78         {
   79             i++;
   80         }
   81     printf("Case %d: %d\n", cnt, i);
   82     cnt++;
   83 } /* FUNCTION process */
   84 
   85 int main()
   86 {
   87     /* main */
   88     int moreToDo;
   89 
   90     init();
   91     moreToDo = getInput();
   92     while (moreToDo)
   93         {
   94             /* while */
   95             process();
   96             moreToDo = getInput();
   97         } /* while */
   98 
   99     return EXIT_SUCCESS;
  100 } /* main */
  101