2001 LSU Computer Science High School Programming Contest

Sponsored by Texas Instruments

Novice - Problem 6, Solution in cpp


/*********************************** 
Paul Miller
Solution to Cube problem
***********************************/

#include <stdio.h>

#define DEBUG (1 == 1)

#define BLACK   7 // 111B
#define CLEAR   0 // 000B

#define RED     4 // 100B
#define GREEN   2 // 010B
#define BLUE    1 // 001B

#define BROWN   6 // 110B
#define AQUA    3 // 011B
#define PURPLE  5 // 101B


int main (void)
{
   int ncubes;
   int side[6];
   int s;
   int whichside;
   int otherside[6];

   otherside[0]=5;
   otherside[1]=4;
   otherside[2]=3;
   otherside[3]=2;
   otherside[4]=1;
   otherside[5]=0;


   scanf(" %d", &ncubes);
   if (DEBUG) printf("Number of cubes %d\n",ncubes);
   for (int l = 0; l < ncubes; l++)
   {
      scanf (" %d", &whichside);
      if (DEBUG) printf("Side to do: %d\n",whichside);
      whichside--;  // convert to subscript
      for (s=0; s<6; s++)
      {
         int tempside;
         scanf ("%d", &tempside);
         switch (tempside)
         {
            case 7:  // red
               side[s] = RED;
            break;

            case 9:  // green
               side[s] = GREEN;
            break;

            case 8:  // blue
               side[s] = BLUE;
            break;

            case 0:  // clear
               side[s] = CLEAR;
            break;

            case 3:  // black
               side[s] = BLACK;
            break;
         }
	if (DEBUG) printf("side: %d\tvalue: %d\tconverted: %d\n", s, tempside, side[s]); 
      }


      //* Now process...
      int col1 = side[whichside];
      int col2 = side[5-whichside];

      if (DEBUG) printf("side: %d(%d)\topposite: %d(%d)\n", whichside, col1, 5-whichside, col2); 

      if (!(col1 ^ BLACK) || !(col2 ^ BLACK))
         printf ("BLACK\n");

      else 
      {
         if (col1 & col2)
            printf ("DARK ");

         col1 |= col2;  // combine bits of both colors

         switch (col1)
         {
            case CLEAR:
               printf ("CLEAR\n");
            break;

            case RED:
               printf ("RED\n");
            break;

            case GREEN:
               printf ("GREEN\n");
            break;

            case BLUE:
               printf ("BLUE\n");
            break;

            case BROWN:
               printf ("BROWN\n");
            break;

            case AQUA:
               printf ("AQUA\n");
            break;

            case PURPLE:
               printf ("PURPLE\n");
            break;

         }
      }
   }  // end for() to read in cubes

   return  0;
}





Return to Problem Index


 

The statements and opinions included in these pages are those of 2001 LSU Computer Science High School Programming Contest only. Any statements and opinions included in these pages are not those of Louisiana State University or the LSU Board of Supervisors.
© 2000,2001 Isaac Traxler
Last modified: Friday, 01 July, 2011 16:27:53