Computer Programming Contest Preparation

ToolBox - Source for: 8/846/a.c



/home/toolbox/public_html/solutions/8/846/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 
   10 #define TRUE  (1 == 1)
   11 #define FALSE (1 != 1)
   12 
   13 #define DEBUG if (FALSE)
   14 
   15 /* fprintf(stderr, "functionName: message", varslist); */
   16 
   17 /*
   18  *  Author: Isaac Traxler
   19  *    Date: 2020-09-08
   20  * Purpose: fun
   21  * Problem: 846
   22  */
   23 
   24 /*
   25  * This template reads data a specified number of times.
   26  */
   27 
   28 int numberOfTimes;
   29 int diff;
   30 
   31 void init()
   32 {
   33     /* FUNCTION init */
   34     scanf("%d ", &numberOfTimes);
   35 } /* FUNCTION init */
   36 
   37 void dump()
   38 {
   39     /* FUNCTION dump */
   40 } /* FUNCTION dump */
   41 
   42 void getInput()
   43 {
   44     /* FUNCTION getInput */
   45     int a;
   46     int b;
   47 
   48     scanf(" %d %d ", &a, &b);
   49     diff = b - a;
   50 } /* FUNCTION getInput */
   51 
   52 long calc(long i)
   53 {
   54     /* FUNCTION calc */
   55     long tmp;
   56 
   57     tmp = (sqrt(4 * i) - 1) + 0.99999999;
   58     return tmp;
   59 } /* FUNCTION calc */
   60 
   61 void process()
   62 {
   63     /* FUNCTION process */
   64     long ans;
   65 
   66     switch (diff)
   67         {
   68             /* switch */
   69         case 0:
   70             ans = 0;
   71             break;
   72         case 1:
   73             ans = 1;
   74             break;
   75         case 2:
   76             ans = 2;
   77             break;
   78         case 3:
   79             ans = 3;
   80             break;
   81         case 4:
   82             ans = 3;
   83             break;
   84         default:
   85             ans = calc(diff);
   86         } /* switch */
   87     printf("%d\n", ans);
   88 } /* FUNCTION process */
   89 
   90 int main()
   91 {
   92     /* main */
   93     int i;
   94 
   95     init();
   96     for (i=0; i<numberOfTimes; i++)
   97         {
   98             /* while */
   99             getInput();
  100             process();
  101         } /* while */
  102 
  103     return EXIT_SUCCESS;
  104 } /* main */
  105 
  106