WA in spoj ONEZERO[closed after ac]


Please explain what is missing or what is wrong.

Problem link: http://www.spoj.com/problems/ONEZERO/

solution: http://ideone.com/16Utzu

Thank you!


changed the solution a bit: http://ideone.com/nJbUXQ

getting segmentation fault now

The length of string temp.s can grow very large. Hence applying atoi to that string will result in integer overflow.