BUY1GET1 - WA

It seems like an easy problem. But somehow, I am getting a WA. I can’t seem to figure out why. Please have a look

A description of my algorithm - Made two arrays A[26] and a[26] for storing the count of upper case and lower case alphabets, respectively. Then traversed through the arrays, adding to the result the sum of element mod 2 and of element/2.

My code:
http://www.codechef.com/viewsolution/3251089

@dhruvmullick :

The problem was that u were separating each line with ‘\n’, but the last line in the test file does not have a ‘\n’. This is what caused WA.

Used scanf() instead and that resulted in AC :slight_smile:

AC Solution: http://www.codechef.com/viewsolution/3251380

2 Likes

Okay, thanks a lot!

@dhruvmullick pls display your gratitude by voting up the answer and accepting it. and your question gonna be closed.

@squal
is there some way to still use fgets() ? Because had this been a string with two words, I wouldn’t have been able to scanf()

@dhruvmullick: u can still do it using scanf scanf(" %[^\n]s",string); http://www.codechef.com/viewsolution/3071269 (its usage) it inputs a string until a user enters a new line character. :slight_smile:

1 Like