Computer Programming Contest Preparation

ToolBox - Source for: 132/13257/a.c



/home/toolbox/public_html/solutions/132/13257/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:
   20  * Purpose: fun
   21  * Problem: 13257
   22  */
   23 
   24 /*
   25  * This template reads data a specified number of times.
   26  */
   27 
   28 #define MAX_SIZE (26*26*26)
   29 #define MAX_LENGTH 10005
   30 
   31 int numberOfTimes;
   32 int cnts[MAX_SIZE];
   33 char buf[MAX_LENGTH];
   34 
   35 void init()
   36 {
   37     /* FUNCTION init */
   38     scanf("%d ", &numberOfTimes);
   39 } /* FUNCTION init */
   40 
   41 void initEach()
   42 {
   43     /* FUNCTION initEach */
   44     int i;
   45 
   46     for (i=0; MAX_SIZE>i; i++)
   47         {
   48             /* for each combo */
   49             cnts[i] = 0;
   50         } /* for each combo */
   51 } /* FUNCTION initEach */
   52 
   53 void dump()
   54 {
   55     /* FUNCTION dump */
   56 } /* FUNCTION dump */
   57 
   58 void getInput()
   59 {
   60     /* FUNCTION getInput */
   61     scanf(" %s ", &buf);
   62 } /* FUNCTION getInput */
   63 
   64 void process()
   65 {
   66     /* FUNCTION process */
   67     int i,j,k;
   68     int t1, t2,t3;
   69     int ln;
   70     int tot;
   71 
   72     initEach();
   73     ln = strlen(buf);
   74     for (i=0; (ln - 2) > i; i++)
   75         {
   76             /* first char */
   77             t1 = 26 * 26 * (buf[i] - 'A');
   78             for (j=i+1; (ln - 1) > j; j++)
   79                 {
   80                     /* second char */
   81                     t2 = 26 * (buf[j] - 'A');
   82                     for (k=j+1; (ln) > k; k++)
   83                         {
   84                             /* third char */
   85                             t3 = buf[k] - 'A';
   86                             cnts[t1+t2+t3]++;
   87                         } /* third char */
   88                 } /* second char */
   89         } /* first char */
   90 
   91     tot = 0;
   92     for (i=0; MAX_SIZE>i; i++)
   93         {
   94             /* for i */
   95             if (0 != cnts[i])
   96                 {
   97                     tot++;
   98                 }
   99         } /* for i */
  100     printf("%d\n", tot);
  101 } /* FUNCTION process */
  102 
  103 int main()
  104 {
  105     /* main */
  106     int i;
  107 
  108     init();
  109     for (i=0; i<numberOfTimes; i++)
  110         {
  111             /* while */
  112             getInput();
  113             process();
  114         } /* while */
  115 
  116     return EXIT_SUCCESS;
  117 } /* main */
  118 
  119