Chef and String (CPCEJC3): Test Case Output Matches but Get Wrong Answer

Hello,

I am trying to solve the problem following problem.

Here is the link to my solution.

The problem statement does not mention you need to lower case the string, but in the give test case it lower case the output so I tried with and without the lower case. The code in the solution above gives the exact same output for the given input. I tried increasing the string length. But it didn’t help.

Here is a solution in C++ that got accepted:
image

I don’t see anything different from what I have done other than the language being in C++. I also read a char before reading the string :
scanf("%c",&string[0]); // clean buffer

I added that because the scanf on the string was not working I searched online and learned that after reading an int you need to read one byte to clean the buffer (read the breakline from the last scanf). I added that and it started reading the string properly.

Please help. I want to understand what I am doing wrong in case I face a similar problem in the future.

Thanks in advance.

What’s wrong in my code
for _ in range(int(input())):

arr=list(map(str,input().split()))

if(len(arr)==1):

    s=arr[0]

    s=s[::-1]

    print(s.lower())

else:

    for i in range(len(arr)):

        s=arr[i]

        s=s[::-1]

        arr[i]=s.lower()

    arr.reverse()

    print(*arr)
1 Like

The Problem Statement is not clear. I can also tell that the problem is not rated (There is no editorial).


It was mentioned in the Input

Next T lines follow an Integer N.

WTH, I can surely tell that the problem is not a standard problem.
@denis_oliveira, you can ignore such problems. Also, I see only few AC submissions, which have exactly similar code.
It looks like there’s a flaw in the Problem.

1 Like

I see, suman_18733097. Thanks for your reply. It is comforting to know the problem was not good. “Next T lines follow an Integer N.”: I noticed this mistake. I think they mean “The next T lined will follow a string S”. I noticed that all submissions in C got rejected. And most of the accepted ones were in CPP. I tried to convert the code to CPP instructions but there were a few minutes left and I didn’t manage to make it.

Hello, Amit… Sorry I can’t help you. I don’t know much of C++. I hope someone else come and help. Good luck.

I suggest you to post the link to your submission. That is one recommendation from codechef to post submissions link and not to paste code on the posts.

1 Like