Computer Programming Contest Preparation

ToolBox - Source for: 125/12502/a.c



/home/toolbox/public_html/solutions/125/12502/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 #include <ctype.h>
   10 
   11 #define TRUE  (1 == 1)
   12 #define FALSE (1 != 1)
   13 
   14 #define DEBUG if (FALSE)
   15 
   16 /* fprintf(stderr, "functionName: message", varslist); */
   17 
   18 /*
   19  *  Author: Isaac Traxler
   20  *    Date: 2025-01-14
   21  * Purpose: fun
   22  * Problem: 12502 - Three Familes
   23  */
   24 
   25 /*
   26  * This template reads data a specified number of times.
   27  *
   28  *
   29 a - hours a worked
   30 b - hours b worked
   31 c - money c will pay
   32 ap - a's pay
   33 
   34 a + b is how many hours it took total
   35 (a + b ) /3 is how many hours each person should have worked
   36 money is distributed by how uch of c's work time a nd b did
   37 
   38 for the case 4 5 90
   39 total_hours = 4 + 5 = 9
   40 c_hours = (a + b) / 3 = 3
   41 
   42 ap = c * (a - c_hours) / c_hours
   43 
   44 or
   45 
   46 ap = c *   a - (a + b)  =   c *   3a - (a + b)   =
   47                -------            ------------
   48                   3                    3
   49           ------------            ------------
   50                a + b                 a + b
   51                -----                 -----
   52                  3                     3
   53 
   54      c *   3a - (a + b)     3    = c *   3a - a - b
   55            ------------ * -----          ----------
   56                 3         a + b             a + b
   57 
   58      c *   2a - b
   59            ------
   60             a + b
   61 
   62 or
   63 
   64 ap = c * (a - (a + b) / 3) / ((a + b) / 3)
   65 
   66 or ap = c * (2 * a - b) / (a + b)
   67 
   68  *
   69  */
   70 
   71 int numberOfTimes;
   72 int a;
   73 int b;
   74 int c;
   75 int ap;
   76 
   77 void init()
   78 {
   79     /* FUNCTION init */
   80     scanf("%d ", &numberOfTimes);
   81 } /* FUNCTION init */
   82 
   83 void dump()
   84 {
   85     /* FUNCTION dump */
   86 } /* FUNCTION dump */
   87 
   88 void getInput()
   89 {
   90     /* FUNCTION getInput */
   91     scanf(" %d %d %d ", &a, &b, &c);
   92 } /* FUNCTION getInput */
   93 
   94 void process()
   95 {
   96     /* FUNCTION process */
   97     ap = c *  ((2 * a) - b) / (a + b);
   98     if (0 > ap)
   99         {
  100             /* make sure they never get less than 0 */
  101             ap = 0;
  102         } /* make sure they never get less than 0 */
  103     printf("%d\n", ap);
  104 } /* FUNCTION process */
  105 
  106 int main()
  107 {
  108     /* main */
  109     int i;
  110 
  111     init();
  112     for (i=0; i<numberOfTimes; i++)
  113         {
  114             /* while */
  115             getInput();
  116             process();
  117         } /* while */
  118 
  119     return EXIT_SUCCESS;
  120 } /* main */
  121 
  122