a little code hack | excellent idea

Okay here i am at 11’O clock totally bored of everything then i said to myself lets code.

I went to the codejam > practice section > Qualification Round Africa 2010. there i find this cute little problem called Problem B. Reverse Words.  the problem was simple we just have to reverse the words in each and every line. I don’t know how others have solved it (may be using gets() and  solving the problem using space comparison and storing the words from space to space) but i solved in a little hack manner.

This is my code

#include <stdio.h>
#include <string.h>
int main()
    int t,i,j;
    char directory[1001][1001], newline[201]={"pdvfksjbdhfjbvkldfjsnvdfjcnovljndfivjndfljvndfjishnvjifdcnlivkjndficvdfjvnaidjusforasdigbvdfhbsgvjhsblvbhkljsgbnklfasgvklisdhfagklhdas"};
    scanf("%d", &t);
    for (i = 0; i < t; ++i)
        for (j = 0; j < 1001; ++j)
            scanf("%s", directory[j]);
            if (strcmp(directory[j],newline)==0)
        printf("Case #%d: ", i+1);
        printf("%s ", directory[j]);
    return 0;

and here’s what i did

instead of going all over the space comparison, i just read the input and printed the output. after observing the code you might wondering that why is comparing every word with that obnoxious string ? i did the text manipulation to the input which is replacing every newline(enter) with newline-obnoxious_string-newline.

after getting this idea i literally jumped from my chair.

i will never forget this(#iwnft)


after seeing the small input problem i am laughing and laughing as they maximum input lines are 5 and maximum input words for each line is 25, which i can do by hand without even using a program in 4 minutes, so it wouldn’t be difficult to get 8 points in codejam Qualification Round Africa 2010.


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