ABCD from SPOJ

Here is the problem:


Can anyone rectify my code? I am getting an NZEC however I have tried all the testcases(available along with the problem and a few mentioned in the comments) with correct outputs. If my code looks extremely complicated and confusing,well I’m sorry for that.

Here is my work:
http://ideone.com/2Wvax7

Thank you.

the problem is that you are taking input string after a line is left…which should not be the case…the input has to be taken in the very next line on the input og N!!!

For your code this input:-

3
ABCD

gives NZEC…!!!

you dont need to take input like this:-

3
                                 //this empty line does not exist in the input file!!!!
ABCD

still to be on the safer side…for ne empty lines in the input file u can use this…

String str=br.readLine();
while(str.length()==0)
    str=br.readLine();

same u can use while taking N as the input to avoid ne initial blank lines…hope this helps…:slight_smile:

1 Like

Hey thanks! Whatever you mentioned was causing the problem,now got an AC :slight_smile:

1 Like

glad could help…:slight_smile: