1 /*
    2  * F - Monkey Vines - GNY ACM Contest 2007
    3  * Solution by: Yury Kholondyrev
    4  *
    5  * Modified by John Buck (October 2007).  Any bugs,
    6  * were undoubtedly added by me -- JB
    7  */
    8 #include <stdio.h>
    9 #include <stdlib.h>
   10 #include <string.h>
   11 
   12 main ()
   13 {
   14   char buf[256];
   15   int i, n, pn, len;
   16   int count, max;
   17 
   18   /* Get problem count */
   19   if (fgets(&(buf[0]), sizeof(buf), stdin) == NULL)
   20     {
   21       return(0);
   22     }
   23 
   24   n = atoi(&(buf[0]));
   25 
   26   for (pn = 1; pn <= n; pn++)
   27     {
   28       if (fgets(&(buf[0]), sizeof(buf), stdin) == NULL || strlen(&(buf[0])) > 150)
   29         {
   30           printf("%d Line too long [%s]\n", pn, &(buf[0]));
   31           continue;
   32         }
   33       count = 0;
   34       max = 0;
   35       len = strlen(&(buf[0]));
   36       for (i = 0; i < len; i++)
   37         {
   38           if (buf[i] == '[')
   39             {
   40               count++;
   41               if (count > max)
   42                 {
   43                   max = count;
   44                 }
   45             }
   46           else if (buf[i] == ']')
   47             {
   48               count--;
   49             }
   50           else
   51             {
   52               break;
   53             }
   54           if (count > 25)
   55             {
   56               printf("%d Too much nesting [%s]\n", pn, &(buf[0]));
   57               continue;
   58             }
   59           if (count < 0)
   60             {
   61               printf("%d Unmatched bracket [%s]\n", pn, &(buf[0]));
   62               continue;
   63             }
   64         }
   65       if (count != 0)
   66         {
   67           printf("%d Unmatched bracket [%s]\n", pn, &(buf[0]));
   68         }
   69       printf("%d %d\n", pn, 1 << max);
   70     }
   71   return(0);
   72 }
   73 
   74