Millionaire


General Statement: Read a set of 15 correct answers for the millionaire game. Then read the contestant’s responses and determine how much money the player wins.

Input: The first line of the data set for this problem is an integer that represents the number of data sets that follow. Each data set consists of 2 lines.
Line #1 is the 15 correct answers for the game, and line #2 is the list of player responses.

Output: Output a dollar sign ($) followed by the amount won.
The output is to be formatted exactly like that for the sample output given below.

Assumptions: All letters are upper case.

Discussion:
Question dollar values:
#1 $100
#2 $200
#3 $300
#4 $500
#5 $1000
#6 $2000
#7 $4000
#8 $8000
#9 $16000
#10 $32000
#11 $64000
#12 $125000
#13 $250000
#14 $500000
#15 $1000000

After question #5, $1000 is guaranteed. After question #10, $32000 is guaranteed.

Sample Input:
3
ABCDABCDABCDABC
ABCDABCA
ABABABCDCDCDBCB
ABABABCDCDA
ABCABCDABCABCDA
ABCABCDABCA

Sample Output:
$1000
$32000
$64000

Solutions :

#include <stdio.h>
#include <string.h>

int main ()
{
    int dataset;
    scanf ("%d", &dataset);
    getchar ();

    while ( dataset-- ) {
        char answer [17];
        gets (answer);

        char response [17];
        gets (response);

        int response_length = strlen (response);
        int j = 0;
        int count = 0;
        bool flag = true;

        for ( int i = 0; i < 15; i++ ) {
            if ( j < response_length ) {
                if ( answer [i] != response [j] ) {
                    flag = false;
                    break;
                }
                else
                    count++;
            }
            j++;
        }

        if ( !flag ) {
            if ( count >= 10 )
                printf ("$32000\n");
            else if ( count >= 5 )
                printf ("$1000\n");
        }

        else {
            switch (count) {
                case 1:
                printf ("$100\n");
                break;

                case 2:
                printf ("$200\n");
                break;

                case 3:
                printf ("$300\n");
                break;

                case 4:
                printf ("$500\n");
                break;

                case 5:
                printf ("$1000\n");
                break;

                case 6:
                printf ("$2000\n");
                break;

                case 7:
                printf ("$4000\n");
                break;

                case 8:
                printf ("$8000\n");
                break;

                case 9:
                printf ("$16000\n");
                break;

                case 10:
                printf ("$32000\n");
                break;

                case 11:
                printf ("$64000\n");
                break;

                case 12:
                printf ("$125000\n");
                break;

                case 13:
                printf ("$250000\n");
                break;

                case 14:
                printf ("$500000\n");
                break;

                case 15:
                printf ("$1000000\n");
                break;
            }
        }
    }

    return 0;
}

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