Need Help! my code is successfully executed in Code,Compile & Run Panel of Codechef but on submission shows Wrong answer. The Question Code is FLOW004 (first and last digit) of Begineer level.And, my code is:

I understand you’re new here. Please take care while pasting codes/linking submissions. Go through posts telling you about features of CC Discuss and then create a new post. Also, humble suggestion please keep the topic short

The link you have share leads to the submit page, not your submission. Your submission can be linked from

Profile > problems solved > your submissions > view (your code)

or

Problem page > my submissions option > view code

this is your code (a link to your most recent submission) Please take notice of this

3 Likes

As for the question, you could convert said number to a list/string type and then add first and last digit

Say your number is 1234 (type int)
convert to type list or str
sum = int(string/list index 0) + int(string/list index -1)
so output will be 1 + 4 = 5
2 Likes

Be careful in the case where N < 10. Here the first and last digits are the same and doing this will lead to a wrong answer. Take care of this edge case separately

1 Like

Thank you so much sir
I am really so much happy that you have responded on my post and sharing your ideas.
And it’s really helpful for me.I will remember everything from next time that you have told.

Thanks again sir😊

1 Like

After little chance in the code my code successful submitted.

Thanks for providing N<10 edge case.

Ok sir
I will try my best from next time🙂.

2 Likes

Hey,I added this condition to my original code after I had submitted once, as when N is,say 5, then N[0] and N[-1] will be same, as the first and last index is same(the only index, in this case) image.
So the output will be twice of what is expected i think, but the problem has pretty weak testcases because it gave me AC even without this condition :thinking:

1 Like

Or maybe that is the answer they wanted? Like for N = 5, expected output could be 10 instead of 5, cause in this case the first and the last digit are both 5 (as seen in above pic) so maybe they were expecting us to add 5 twice…

Yep. @anon11076894 i submitted the following code and it gave WA:

T = int(input())
for i in range(T):
	A = input()
	if(int(A) > 9):
		print(int(A[0]) + int(A[-1]))
	else:
		print(int(A[0]))

So yeah, the if condition is NOT to be used here @santosh_ks15

1 Like

After changing few statements my code was successful submitted
Submitted code

nice, but this line is still not required…

if(t>=1 && t<=1000)

CONSTRAINTS ARE GIVEN TO GIVE YOU A HINT OF TIME COMPLEXITY. IT IS ‘GUARANTEED’ THAT THE TEST CASES WILL BE WITHIN THESE TEST CASES. YOU DO NOT NEED A CONDITION TO CHECK THIS

2 Likes

Ok
Thanks again for all your ideas :blush::blush:

1 Like

you’re very welcome. Keep coding!

1 Like

@wicked_knight

t = int(input())
while t > 0:
	n = input()
	list = [int(x) for x in str(n)]
	if len(list) == 1:
		print(n)
	else:
		print(int(n[0]) + int(n[-1]))
	t -= 1

here is my AC code and I have used the condition.

why do i get WA for the same code? CodeChef: Practical coding for everyone

@admin why does the same code show WA and AC for two different users?!

may be test cases were updated between @anon11076894 submission and your submission, and for single digit numbers (len(l)==1) both first and last digits are same, so answer should be 2*number.

1 Like

exactly, that’s what I thought.

but this is not possible, because I had submitted the code (with condition of len(string) == 1 once before him also, and it gave me WA. Also, our recent submission was not very far apart, and since this is a fairly old problem of practice beginner, i hardly think they’ll be changing anything rn

He submitted in 2019, and you in 2020, but this questions has submissions from 2015, so i also don’t think that they would have changed anything after 4 years.

1 Like

lol sorry i just saw 20-08 and assumed 2020 XD