FLOW006- Sum of digits

Hi. I have submitted my code five times for this question. But it gives me ‘Wrong Answer’ all the time. I have tried many test cases and it gives me the right output. Can you please help me.

Question: https://www.codechef.com/problems/FLOW006

My solution: https://www.codechef.com/viewsolution/14541812
Thanks in advance.

String s = scan.nextLine();
sum += Integer.parseInt(Character.toString(s.charAt(i)));

hey @ramakrishna_5 logically there is no mistake in your code,but output format is wrong.

printf("\n%ld",sum[i]); should be replaced by printf("%ld\n",sum[i]);

Remove that checking for constraints. I just turned those 2 “if” statements into comments and your code got AC.

The problem statement does not state correct constraints.

(BTW, thanks for pointing my error c_utkarsh . Seeing too many Q at the same time does that mismatch XD)


you also changed this printf("\n%ld",sum[i]);

Ya, that format seems weird to me XD. But most probably it shouldnt be that new line. The judge is expected to be tolerant to 1-2 extra new line here and there.

But then, its expected that statement abides by the constraint as well…