Computer Programming Contest Preparation

ToolBox - Source for: 105/10583/a.c



/home/toolbox/public_html/solutions/105/10583/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: 10583
   20  */
   21 
   22 /*
   23  * This template reads data until a terminating value is reached.
   24  */
   25 
   26 #define MAXPEOPLE 500001
   27 
   28 int ary[MAXPEOPLE];
   29 int m, n;
   30 
   31 int init()
   32 {
   33     /* FUNCTION init */
   34     int i;
   35 
   36     for (i = 0; i < MAXPEOPLE; i ++)
   37         {
   38             ary[i] = 0;
   39         }
   40 } /* FUNCTION init */
   41 
   42 int dump()
   43 {
   44     /* FUNCTION dump */
   45 } /* FUNCTION dump */
   46 
   47 int getInput()
   48 {
   49     /* FUNCTION getInput */
   50     int dataReadFlag;
   51     scanf(" %d %d", &n, &m);
   52     dataReadFlag = (0 != m || 0 != n);
   53     return (dataReadFlag);
   54 } /* FUNCTION getInput */
   55 
   56 void process()
   57 {
   58     /* FUNCTION process */
   59     int i;
   60     int thing1;
   61     int thing2;
   62 
   63     for (i = 0; i < m; i ++)
   64         {
   65             scanf(" %d %d", &thing1, &thing2);
   66             /*ary[max(thing1, thing2)] = ary[min(thing1, thing2)];*/
   67 
   68             /*
   69             *case 1: Both array locations have the original values.
   70             *
   71             *case 2: Both array locations have the same value.
   72             *case 3: First array location has it's original value, but the second one does not.
   73             *case 4: Second array location has it's original value, but the first one does not.
   74             *case 5: Both have new(not original) values.
   75             */
   76             if (1 == ary[thing1] && 1 == ary[thing2])
   77                 {
   78                     ary[max(thing1, thing2)] = -1*min(thing1, thing2);
   79                     ary[min(thing1, thing2)] = 2;
   80                 }
   81             else if (0 > ary[thing1] && 1 == ary[thing2])
   82                 {
   83                     ary[-1*thing1]++;
   84                     ary[thing2] = ary[thing1];
   85                 }
   86             else if (0 > ary[thing2] && 1 == ary[thing1])
   87                 {
   88                     ary[-1*thing2]++;
   89                     ary[thing1] = ary[thing2];
   90                 }
   91             else if (0 > ary[thing1] &&  0 > ary[thing2])
   92                 {
   93                     ary[thing1] = ary[thing2];
   94                 }
   95             else if ()
   96 
   97                 /*if (ary[thing1] == ary[thing2])*/
   98             }
   99 } /* FUNCTION process */
  100 
  101 int main ()
  102 {
  103     /* main */
  104     int moreToDo;
  105 
  106     init();
  107     moreToDo = getInput();
  108     while (moreToDo)
  109         {
  110             /* while */
  111             process();
  112             moreToDo = getInput();
  113         } /* while */
  114 
  115     return EXIT_SUCCESS;
  116 } /* main */
  117