Spelling Bee


TCEA State Programming Contest
April 28, 2001

Problem 5.2 Spelling Bee

General Statement: Given a pair of words (the first is the correct spelling and the second is the contestant’s spelling of the word) determine if the word is spelled correctly.

The degree of correctness is as follows:
CORRECT if it is an exact match
ALMOST CORRECT if no more than 2 letters are wrong
WRONG if 3 or more letters are wrong

Input: The first line of the data set for this problem is an integer that represents the number of pairs of words in the list. Each word is on a separate line.

Output: Output the contestant’s spelling of the word and the rating. All letters are upper case.

The output is to be formatted exactly like that for the sample output given below.

Assumptions: Words contain only upper case letters. The maximum word length is 10.

Sample Input:
3
SAMPLE
SIMPLE
THEIR
THEIR
WINDMILL
WINDOWS

Sample Output:
SIMPLE IS ALMOST CORRECT
THEIR IS CORRECT
WINDOWS IS WRONG

Solutions:

#include
#include

int main ()
{
int dataSet;
scanf (“%d”, &dataSet);

while ( dataSet– ) {

char correct_spelling [12];
char contestant_spelling [12];
int count = 0;

scanf (“%s %s”, correct_spelling, contestant_spelling);

int big_length = strlen (correct_spelling) > strlen (contestant_spelling) ? strlen (correct_spelling) : strlen (contestant_spelling);
int small_length = strlen (correct_spelling) > strlen (contestant_spelling) ? strlen (contestant_spelling) : strlen (correct_spelling);

for ( int i = 0; i < big_length; i++ ) { if ( i < small_length ) { if ( correct_spelling [i] != contestant_spelling [i] ) count++; } else count++; } if ( !count ) printf ("%s IS CORRECT\n", contestant_spelling); else if ( count <= 2 ) printf ("%s IS ALMOST CORRECT\n", contestant_spelling); else printf ("%s IS WRONG\n", contestant_spelling); } return 0; } [/sourcecode]

Advertisements

One thought on “Spelling Bee

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s