Computer Programming Contest Preparation

ToolBox - Source for: 120/12036/a.c



/home/toolbox/public_html/solutions/120/12036/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: 2016-02-02
   20  * Purpose: fun
   21  * Problem: 12036 - Stable Grid
   22  */
   23 
   24 /*
   25  * This template reads data a specified number of times.
   26  */
   27 
   28 #define MAX_VALUES 102
   29 
   30 int numberOfTimes;
   31 int ary[MAX_VALUES];
   32 int sze;
   33 
   34 
   35 void init()
   36 {
   37     /* FUNCTION init */
   38     scanf("%d ", &numberOfTimes);
   39 } /* FUNCTION init */
   40 
   41 void dump()
   42 {
   43     /* FUNCTION dump */
   44 } /* FUNCTION dump */
   45 
   46 void getInput()
   47 {
   48     /* FUNCTION getInput */
   49     int i;
   50     int t;
   51 
   52     scanf(" %d ", &sze);
   53     /* empty count list first */
   54     for (i=0; i<MAX_VALUES; i++)
   55         {
   56             ary[i] = 0;
   57         }
   58     /* process matrix */
   59     for (i=0; i<(sze*sze); i++)
   60         {
   61             /* for each value */
   62             scanf(" %d ", &t);
   63             ary[t] = ary[t] + 1;
   64         } /* for each value */
   65 
   66 } /* FUNCTION getInput */
   67 
   68 void process()
   69 {
   70     /* FUNCTION process */
   71     int i;
   72     int flag = TRUE;
   73 
   74     for (i=0; (i<MAX_VALUES) && (flag); i++)
   75         {
   76             /* make sure no value occurs more than width of a row */
   77             flag = ary[i] <= sze;
   78         } /* make sure no value occurs more than width of a row */
   79     if (flag)
   80         {
   81             printf("yes\n");
   82         }
   83     else
   84         {
   85             printf("no\n");
   86         }
   87 } /* FUNCTION process */
   88 
   89 int main()
   90 {
   91     /* main */
   92     int i;
   93 
   94     init();
   95     for (i=0; i<numberOfTimes; i++)
   96         {
   97             /* while */
   98             getInput();
   99             printf("Case %d: ", i+1);
  100             process();
  101         } /* while */
  102 
  103     return EXIT_SUCCESS;
  104 } /* main */
  105 
  106