SIGSEGV error in JNEXT of spoj

The link to my code of JNEXT of spoj is GvvvrN - Online C++ Compiler & Debugging Tool - Ideone.com
And I have followed the steps given in Algorithm to find next greater permutation of a given string - Stack Overflow . But still this solution is giving me run time error.
Please help me out.And thanks in advance.