NITIKA- WA

Question Link

My solution

I dont know in what condition it will show wrong answer???

I think your answer is wrong because of string input …check my solution …i have taken input twice if on 1st attempt it fails.
https://www.codechef.com/viewsolution/14524162

Hey @root00198

The logic which you have written is correct but you are getting a WA because there is a mistake while taking the inputs. Even the test case given in the problem statement is not getting passed with your code because you are reading only T-1 strings.

We should be careful while using getline() function as it reads the ‘\n’ character as well. In your code the first string that you read in the while loop is an empty string and thus you are not able to read the last string of test cases. This problem can easily be solved using getchar() function to take care of the ‘\n’ character. Here is the link for your working code with just the addition of getchar() function at the correct place.

@ayush_7 Mate, it is not appropriate to say “i have taken input twice if on 1st attempt it fail.” It is a deterministic computer code with standard input format. So either you take input or you don’t. There is nothing like if it “fails”. It is not some stochastic input. Consuming extra characters while taking input is a different issue and should be conveyed appropriately.

1 Like