Anything You Can Do, I Can Do Better


General Statement:
You have a colleague that is extremely competitive and always tries to “top” one of your stories. If you say your car is fast, your colleague will say his or her car is faster. If you say your car is faster, your colleague will say his or her car is fastest. After a few such conversations, you realize that you can always predict what your colleague will say next.

To demonstrate how annoying this is, you decide to write a program that can accurately predict the responses of your colleague. Your task is to write this program. Specifically, given any adjective, your program will return its comparative form by appending “er” to it. Note that if the adjective already ends in “e”, you should only append “r”. If your program is given an adjective already in its comparative form, your program should return the superlative form of the adjective created by simply replacing the “er” with “est”. Your program should consider any string that ends in “er” to be an adjective in comparative form.

Input:
The first line of the input contains an integer n that represents the number of data collections that follow where each data collection is on a single line. Each input line contains a string representing an adjective or its comparative form. Each string will be given in all lower case letters.

Output:
Your program should produce n lines of output (one for each data collection). Each line should be in lower case letters. If the input is the comparative form of an adjective (ends in “er”), your program should output the superlative form.

Otherwise, your program should output the comparative form of the string given as input.

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

Assumptions:
The value of n will be between 1 and 100, inclusive.
Each input word will have between 1 and 30 characters, inclusive.

Sample Input:
3
warm
smaller
rare

Sample Output:
warmer
smallest
rarer

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

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

    while ( dataset--) {
        char input [35];
        scanf ("%s", input);

        int length = strlen (input);

        if ( input [length - 1] == 'r' && input [length - 2] == 'e' ) {
            input [length - 1] = 's';
            input [length] = 't';
            input [length + 1] = 0;
        }

        else {
            if ( input [length - 1] == 'e' )
                strcat (input, "r");
            else
                strcat (input, "er");
        }

        printf ("%s\n", input);

    }

    return 0;
}

2 thoughts on “Anything You Can Do, I Can Do Better

  1. Judge's Input : 
    happier
    fierce
    fiercer	
    late
    earlier
    new
    friendlier
    slow
    fierier
    
    Judge's Output :
    happiest
    fiercer
    fiercest
    later
    earliest
    newer
    friendliest
    slower
    fieriest
    

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