Computer Programming Contest Preparation

ToolBox - Source for: 127/12751/a.c



/home/toolbox/public_html/solutions/127/12751/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: 2015-09-29
   20  * Purpose: fun
   21  * Problem: 12751
   22  */
   23 
   24 /*
   25  * This template reads data a specified number of times.
   26  */
   27 
   28 int numberOfTimes;
   29 int N;
   30 int K;
   31 int X;
   32 
   33 void init()
   34 {
   35     /* FUNCTION init */
   36     scanf("%d ", &numberOfTimes);
   37 } /* FUNCTION init */
   38 
   39 void dump()
   40 {
   41     /* FUNCTION dump */
   42 } /* FUNCTION dump */
   43 
   44 void getInput()
   45 {
   46     /* FUNCTION getInput */
   47     scanf(" %d %d %d ", &N, &K, &X);
   48 } /* FUNCTION getInput */
   49 
   50 int calc(int i)
   51 {
   52     /* FUNCTION calc */
   53     return (((i + 1) * i) / 2);
   54 } /* FUNCTION calc */
   55 
   56 void process()
   57 {
   58     /* FUNCTION process */
   59     int total;
   60     /*
   61      sum(N) - sum(X+K-1) + sum(X)
   62     */
   63     DEBUG printf("calc(%d) = %d\n", N, calc(N));
   64     DEBUG printf("calc(%d) = %d\n", X+K-1, calc(X+K-1));
   65     DEBUG printf("calc(%d) = %d\n", X-1, calc(X-1));
   66     total = calc(N) - calc(X+K-1) + calc(X-1);
   67     printf("%d\n", total);
   68 } /* FUNCTION process */
   69 
   70 int main()
   71 {
   72     /* main */
   73     int i;
   74 
   75     init();
   76     for (i=1; i<=numberOfTimes; i++)
   77         {
   78             /* while */
   79             getInput();
   80             printf("Case %d: ", i);
   81             process();
   82         } /* while */
   83 
   84     return EXIT_SUCCESS;
   85 } /* main */
   86 
   87