runtime error sigsegv

when i run it on ideone the code runs successfully but spoj gives me runtime error sigsegv can somebody tell what is wrong with my code ideone.com/KOy4F0

SIGSEGV is an error caused by an invalid memory reference or segmentation fault.

ReCheck your while loop

	while(s.top() != 'N'){
	s.pop();
	out += s.top(); 
}

When there is only 1 element in ā€˜sā€™ i.e. for the last iteration

and after you

s.pop()

ā€˜sā€™ becomes empty.

thus in the next line

out+=s.top()

s.top() points to an invalid memory.

Hope this helps.

If this solution solves your problem kindly Accept it using the tick option below the downvote button. Happy coding :slight_smile: