Computer Programming Contest Preparation

ToolBox - Source for: 109/10935/a.c



/home/toolbox/public_html/solutions/109/10935/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: Isaac Traxler
   17  *    Date: 2016-09-11
   18  * Purpose: fun
   19  * Problem: 10935 - Throwing Cards Away I
   20  */
   21 
   22 /*
   23  * This template reads data until a terminating value is reached.
   24  */
   25 
   26 #define MAX 125
   27 int a[MAX];
   28 int card;
   29 
   30 void init(int x)
   31 {
   32     /* FUNCTION init */
   33     int i;
   34 
   35     for (i=1; x>=i; i++)
   36         {
   37             /* for each card */
   38             a[i] = i;
   39         } /* for each card */
   40 } /* FUNCTION init */
   41 
   42 void dump()
   43 {
   44     /* FUNCTION dump */
   45 } /* FUNCTION dump */
   46 
   47 int getInput()
   48 {
   49     /* FUNCTION getInput */
   50     int dataReadFlag;
   51 
   52     scanf(" %d ", &card);
   53     dataReadFlag = (0 != card);
   54     return (dataReadFlag);
   55 } /* FUNCTION getInput */
   56 
   57 void process()
   58 {
   59     /* FUNCTION process */
   60     int bot;
   61     int top = 1;
   62 
   63     bot = card;
   64     if (bot == top)
   65         {
   66             /* handle case of 1 card */
   67             printf("Discarded cards:");
   68         } /* handle case of 1 card */
   69     else
   70         {
   71             /* normal case */
   72             printf("Discarded cards: %d", a[top]);
   73             top++;
   74         } /* normal case */
   75     while (bot > top)
   76         {
   77             /* while */
   78             bot++;
   79             a[bot] = a[top];
   80             top++;
   81             printf(", %d", a[top]);
   82             top++;
   83         } /* while */
   84     printf("\nRemaining card: %d\n", a[top]);
   85 } /* FUNCTION process */
   86 
   87 int main()
   88 {
   89     /* main */
   90     int moreToDo;
   91 
   92     moreToDo = getInput();
   93     while (moreToDo)
   94         {
   95             /* while */
   96             init(card);
   97             process();
   98             moreToDo = getInput();
   99         } /* while */
  100 
  101     return EXIT_SUCCESS;
  102 } /* main */
  103