1999 High School Programming Contest

Problem 6 – A Breakthrough in Computer Humor: Cheesy or Corny

Solution

//
//  University of Evansville ACM
//  1999 High School Programming Contest
//
//  Saturday April 17, 1999
//
//  Problem 6 - A Breakthrough in Computer Humor: Cheesy or Corny
//
#include <iostream.h>
#include <string.h>

/*********
	Note to code-reader:  Since C++ starts strings with a character zero,
any test to determine whether an index is odd tells whether the character
is in an even position, and vice-versa.
*********/


int main()
{
   char input[257];  //256 characters plus one null character

	//Boolean values to be proven
   bool quotes = false,
   	  cheesy = false,
        corny = false;

   //Boolean value to be disproven
   bool even_vowel = true;

   int num_vowels = 0,      //the number of vowels
   	 num_capitals = 0,	 //the number of capitals
       num_punct = 0,		 //the number of punctuation marks
       num_words = 0, 		 //the number of words
       max_letters = 0,     //number of letters in largest word
       last_punct = -1;		 //intermediate used to keep track of the position
       							 //of the last punctuation mark
                            //used to determine words, thus we must have a value
                            //of -1 in case a word and not punctuation starts

	cout << "Please enter string to be evaluated:\n";
	cin.getline(input, 256);

   //Begin evaluation
   if (input[0] == '"' && input[strlen(input) - 1] == '"')
   	quotes = true;
   bool exit = false; //loop control variable
   for (int i = 0; !exit; i++)
   {
   	if (input[i] >= 'A' && input[i] <= 'Z')
      	num_capitals++;
      switch (input[i])
      {
      	case 'A':
      	case 'E':
      	case 'I':
      	case 'O':
      	case 'U':
         case 'a':
         case 'e':
         case 'i':
         case 'o':
         case 'u':
         	num_vowels++;
            //if i is even, the vowel is odd
            if (i%2 == 0) even_vowel = false;
            break;
			case '\0':
         	// '\0' counts as punctuation, b/c we might have to count the last word
            num_punct--; //counter-acts increment below
            exit = true;
				//no break lets the following code to be used after case ',':
         case '!':
         case '.':
         case ',':
         case '?':
         case '"':
         case ' ':
         case ';':
				num_punct++;
            //if word is between punctuation, increment num_word and
            //calculate its length
            if ( (i - last_punct ) != 1) {
            	num_words++;
               if ( (i - last_punct - 1) > max_letters)
               	max_letters = i - last_punct - 1;
            } //end if
            if (input[i] != '\0') last_punct = i;
            break;
      }//end switch

   }//end for
   if (num_vowels == 2 ||
       num_vowels == 4 ||
       num_vowels == 8 ||
       num_vowels == 16 ||
		 num_vowels == 32 ||
       num_vowels == 64 ||
       num_vowels == 128 ||
       num_vowels == 256 ) cheesy = true;
   if (num_punct%4 == 0 && num_punct > 0) cheesy = true;
   if (num_capitals == 2) cheesy = true;

   if (num_capitals == 1 || quotes || even_vowel) corny = true;
   if (max_letters == num_words) corny = true;

   cout << "Result: ";

   if(corny && cheesy)
   	cout << "Corny and Cheesy" << endl;
	 else if (cheesy)
   	cout << "Cheesy" << endl;
   else if (corny)
   	cout << "Corny" << endl;
   else
   	cout << "Not Funny";

   return 0;
}

Judges' Test Data

Test #1

Input

ELALILOLULILELE

Output

Cheesy

Test #2

Input

!E'L"P?E

Output

Corny and Cheesy

Test #3

Input

exactly TWo

Output

Cheesy

Test #4

Input

almost oNe

Output

Cheesy and Corny

Test #5

Input

is this four now

Output

Corny

Test #6

Input

The Nuclear Chicken rules the Earth.

Output

Not funny.